summaryrefslogtreecommitdiffstats
path: root/Modules/clinic/pyexpat.c.h
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2023-11-07 22:36:13 (GMT)
committerGitHub <noreply@github.com>2023-11-07 22:36:13 (GMT)
commit11e83488c5a4a6e75a4f363a2e1a45574fd53573 (patch)
tree4d3ad20c063f098a2b142aace0baade00e465ac9 /Modules/clinic/pyexpat.c.h
parentea970fb116a114f2c47cc8f21df00166d43ab78b (diff)
downloadcpython-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 'Modules/clinic/pyexpat.c.h')
-rw-r--r--Modules/clinic/pyexpat.c.h37
1 files changed, 31 insertions, 6 deletions
diff --git a/Modules/clinic/pyexpat.c.h b/Modules/clinic/pyexpat.c.h
index 4fac03e..a5b93e6 100644
--- a/Modules/clinic/pyexpat.c.h
+++ b/Modules/clinic/pyexpat.c.h
@@ -129,10 +129,15 @@ pyexpat_xmlparser_SetBase(xmlparseobject *self, PyObject *arg)
_PyArg_BadArgument("SetBase", "argument", "str", arg);
goto exit;
}
- base = PyUnicode_AsUTF8(arg);
+ Py_ssize_t base_length;
+ base = PyUnicode_AsUTF8AndSize(arg, &base_length);
if (base == NULL) {
goto exit;
}
+ if (strlen(base) != (size_t)base_length) {
+ PyErr_SetString(PyExc_ValueError, "embedded null character");
+ goto exit;
+ }
return_value = pyexpat_xmlparser_SetBase_impl(self, base);
exit:
@@ -223,10 +228,15 @@ pyexpat_xmlparser_ExternalEntityParserCreate(xmlparseobject *self, PyTypeObject
context = NULL;
}
else if (PyUnicode_Check(args[0])) {
- context = PyUnicode_AsUTF8(args[0]);
+ Py_ssize_t context_length;
+ context = PyUnicode_AsUTF8AndSize(args[0], &context_length);
if (context == NULL) {
goto exit;
}
+ if (strlen(context) != (size_t)context_length) {
+ PyErr_SetString(PyExc_ValueError, "embedded null character");
+ goto exit;
+ }
}
else {
_PyArg_BadArgument("ExternalEntityParserCreate", "argument 1", "str or None", args[0]);
@@ -239,10 +249,15 @@ pyexpat_xmlparser_ExternalEntityParserCreate(xmlparseobject *self, PyTypeObject
_PyArg_BadArgument("ExternalEntityParserCreate", "argument 2", "str", args[1]);
goto exit;
}
- encoding = PyUnicode_AsUTF8(args[1]);
+ Py_ssize_t encoding_length;
+ encoding = PyUnicode_AsUTF8AndSize(args[1], &encoding_length);
if (encoding == NULL) {
goto exit;
}
+ if (strlen(encoding) != (size_t)encoding_length) {
+ PyErr_SetString(PyExc_ValueError, "embedded null character");
+ goto exit;
+ }
skip_optional_posonly:
return_value = pyexpat_xmlparser_ExternalEntityParserCreate_impl(self, cls, context, encoding);
@@ -403,10 +418,15 @@ pyexpat_ParserCreate(PyObject *module, PyObject *const *args, Py_ssize_t nargs,
encoding = NULL;
}
else if (PyUnicode_Check(args[0])) {
- encoding = PyUnicode_AsUTF8(args[0]);
+ Py_ssize_t encoding_length;
+ encoding = PyUnicode_AsUTF8AndSize(args[0], &encoding_length);
if (encoding == NULL) {
goto exit;
}
+ if (strlen(encoding) != (size_t)encoding_length) {
+ PyErr_SetString(PyExc_ValueError, "embedded null character");
+ goto exit;
+ }
}
else {
_PyArg_BadArgument("ParserCreate", "argument 'encoding'", "str or None", args[0]);
@@ -421,10 +441,15 @@ pyexpat_ParserCreate(PyObject *module, PyObject *const *args, Py_ssize_t nargs,
namespace_separator = NULL;
}
else if (PyUnicode_Check(args[1])) {
- namespace_separator = PyUnicode_AsUTF8(args[1]);
+ Py_ssize_t namespace_separator_length;
+ namespace_separator = PyUnicode_AsUTF8AndSize(args[1], &namespace_separator_length);
if (namespace_separator == NULL) {
goto exit;
}
+ if (strlen(namespace_separator) != (size_t)namespace_separator_length) {
+ PyErr_SetString(PyExc_ValueError, "embedded null character");
+ goto exit;
+ }
}
else {
_PyArg_BadArgument("ParserCreate", "argument 'namespace_separator'", "str or None", args[1]);
@@ -473,4 +498,4 @@ exit:
#ifndef PYEXPAT_XMLPARSER_USEFOREIGNDTD_METHODDEF
#define PYEXPAT_XMLPARSER_USEFOREIGNDTD_METHODDEF
#endif /* !defined(PYEXPAT_XMLPARSER_USEFOREIGNDTD_METHODDEF) */
-/*[clinic end generated code: output=bfc1f3d3e2cbc8dc input=a9049054013a1b77]*/
+/*[clinic end generated code: output=48c4296e43777df4 input=a9049054013a1b77]*/