diff options
author | Victor Stinner <vstinner@python.org> | 2023-11-07 22:36:13 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-07 22:36:13 (GMT) |
commit | 11e83488c5a4a6e75a4f363a2e1a45574fd53573 (patch) | |
tree | 4d3ad20c063f098a2b142aace0baade00e465ac9 /Tools | |
parent | ea970fb116a114f2c47cc8f21df00166d43ab78b (diff) | |
download | cpython-11e83488c5a4a6e75a4f363a2e1a45574fd53573.zip cpython-11e83488c5a4a6e75a4f363a2e1a45574fd53573.tar.gz cpython-11e83488c5a4a6e75a4f363a2e1a45574fd53573.tar.bz2 |
gh-111089: Revert PyUnicode_AsUTF8() changes (#111833)
* Revert "gh-111089: Use PyUnicode_AsUTF8() in Argument Clinic (#111585)"
This reverts commit d9b606b3d04fc56fb0bcc479d7d6c14562edb5e2.
* Revert "gh-111089: Use PyUnicode_AsUTF8() in getargs.c (#111620)"
This reverts commit cde1071b2a72e8261ca66053ef61431b7f3a81fd.
* Revert "gh-111089: PyUnicode_AsUTF8() now raises on embedded NUL (#111091)"
This reverts commit d731579bfb9a497cfb0076cb6b221058a20088fe.
* Revert "gh-111089: Add PyUnicode_AsUTF8() to the limited C API (#111121)"
This reverts commit d8f32be5b6a736dc2fc9dca3f1bf176c82fc9b44.
* Revert "gh-111089: Use PyUnicode_AsUTF8() in sqlite3 (#111122)"
This reverts commit 37e4e20eaa8f27ada926d49e5971fecf0477ad26.
Diffstat (limited to 'Tools')
-rwxr-xr-x | Tools/clinic/clinic.py | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index 4f238a3..5f94b90a 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -4350,23 +4350,34 @@ class str_converter(CConverter): {bad_argument} goto exit; }}}} - {paramname} = PyUnicode_AsUTF8({argname}); + Py_ssize_t {length_name}; + {paramname} = PyUnicode_AsUTF8AndSize({argname}, &{length_name}); if ({paramname} == NULL) {{{{ goto exit; }}}} + if (strlen({paramname}) != (size_t){length_name}) {{{{ + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + }}}} """, argname=argname, - bad_argument=self.bad_argument(displayname, 'str', limited_capi=limited_capi)) + bad_argument=self.bad_argument(displayname, 'str', limited_capi=limited_capi), + length_name=self.length_name) if self.format_unit == 'z': return self.format_code(""" if ({argname} == Py_None) {{{{ {paramname} = NULL; }}}} else if (PyUnicode_Check({argname})) {{{{ - {paramname} = PyUnicode_AsUTF8({argname}); + Py_ssize_t {length_name}; + {paramname} = PyUnicode_AsUTF8AndSize({argname}, &{length_name}); if ({paramname} == NULL) {{{{ goto exit; }}}} + if (strlen({paramname}) != (size_t){length_name}) {{{{ + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + }}}} }}}} else {{{{ {bad_argument} @@ -4374,7 +4385,8 @@ class str_converter(CConverter): }}}} """, argname=argname, - bad_argument=self.bad_argument(displayname, 'str or None', limited_capi=limited_capi)) + bad_argument=self.bad_argument(displayname, 'str or None', limited_capi=limited_capi), + length_name=self.length_name) return super().parse_arg(argname, displayname, limited_capi=limited_capi) # |