summaryrefslogtreecommitdiffstats
path: root/Modules/clinic/_localemodule.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/_localemodule.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/_localemodule.c.h')
-rw-r--r--Modules/clinic/_localemodule.c.h72
1 files changed, 61 insertions, 11 deletions
diff --git a/Modules/clinic/_localemodule.c.h b/Modules/clinic/_localemodule.c.h
index 2663b28..5e0880b 100644
--- a/Modules/clinic/_localemodule.c.h
+++ b/Modules/clinic/_localemodule.c.h
@@ -37,10 +37,15 @@ _locale_setlocale(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
locale = NULL;
}
else if (PyUnicode_Check(args[1])) {
- locale = PyUnicode_AsUTF8(args[1]);
+ Py_ssize_t locale_length;
+ locale = PyUnicode_AsUTF8AndSize(args[1], &locale_length);
if (locale == NULL) {
goto exit;
}
+ if (strlen(locale) != (size_t)locale_length) {
+ PyErr_SetString(PyExc_ValueError, "embedded null character");
+ goto exit;
+ }
}
else {
_PyArg_BadArgument("setlocale", "argument 2", "str or None", args[1]);
@@ -225,10 +230,15 @@ _locale_gettext(PyObject *module, PyObject *arg)
_PyArg_BadArgument("gettext", "argument", "str", arg);
goto exit;
}
- in = PyUnicode_AsUTF8(arg);
+ Py_ssize_t in_length;
+ in = PyUnicode_AsUTF8AndSize(arg, &in_length);
if (in == NULL) {
goto exit;
}
+ if (strlen(in) != (size_t)in_length) {
+ PyErr_SetString(PyExc_ValueError, "embedded null character");
+ goto exit;
+ }
return_value = _locale_gettext_impl(module, in);
exit:
@@ -267,10 +277,15 @@ _locale_dgettext(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
domain = NULL;
}
else if (PyUnicode_Check(args[0])) {
- domain = PyUnicode_AsUTF8(args[0]);
+ Py_ssize_t domain_length;
+ domain = PyUnicode_AsUTF8AndSize(args[0], &domain_length);
if (domain == NULL) {
goto exit;
}
+ if (strlen(domain) != (size_t)domain_length) {
+ PyErr_SetString(PyExc_ValueError, "embedded null character");
+ goto exit;
+ }
}
else {
_PyArg_BadArgument("dgettext", "argument 1", "str or None", args[0]);
@@ -280,10 +295,15 @@ _locale_dgettext(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
_PyArg_BadArgument("dgettext", "argument 2", "str", args[1]);
goto exit;
}
- in = PyUnicode_AsUTF8(args[1]);
+ Py_ssize_t in_length;
+ in = PyUnicode_AsUTF8AndSize(args[1], &in_length);
if (in == NULL) {
goto exit;
}
+ if (strlen(in) != (size_t)in_length) {
+ PyErr_SetString(PyExc_ValueError, "embedded null character");
+ goto exit;
+ }
return_value = _locale_dgettext_impl(module, domain, in);
exit:
@@ -322,10 +342,15 @@ _locale_dcgettext(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
domain = NULL;
}
else if (PyUnicode_Check(args[0])) {
- domain = PyUnicode_AsUTF8(args[0]);
+ Py_ssize_t domain_length;
+ domain = PyUnicode_AsUTF8AndSize(args[0], &domain_length);
if (domain == NULL) {
goto exit;
}
+ if (strlen(domain) != (size_t)domain_length) {
+ PyErr_SetString(PyExc_ValueError, "embedded null character");
+ goto exit;
+ }
}
else {
_PyArg_BadArgument("dcgettext", "argument 1", "str or None", args[0]);
@@ -335,10 +360,15 @@ _locale_dcgettext(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
_PyArg_BadArgument("dcgettext", "argument 2", "str", args[1]);
goto exit;
}
- msgid = PyUnicode_AsUTF8(args[1]);
+ Py_ssize_t msgid_length;
+ msgid = PyUnicode_AsUTF8AndSize(args[1], &msgid_length);
if (msgid == NULL) {
goto exit;
}
+ if (strlen(msgid) != (size_t)msgid_length) {
+ PyErr_SetString(PyExc_ValueError, "embedded null character");
+ goto exit;
+ }
category = PyLong_AsInt(args[2]);
if (category == -1 && PyErr_Occurred()) {
goto exit;
@@ -375,10 +405,15 @@ _locale_textdomain(PyObject *module, PyObject *arg)
domain = NULL;
}
else if (PyUnicode_Check(arg)) {
- domain = PyUnicode_AsUTF8(arg);
+ Py_ssize_t domain_length;
+ domain = PyUnicode_AsUTF8AndSize(arg, &domain_length);
if (domain == NULL) {
goto exit;
}
+ if (strlen(domain) != (size_t)domain_length) {
+ PyErr_SetString(PyExc_ValueError, "embedded null character");
+ goto exit;
+ }
}
else {
_PyArg_BadArgument("textdomain", "argument", "str or None", arg);
@@ -421,10 +456,15 @@ _locale_bindtextdomain(PyObject *module, PyObject *const *args, Py_ssize_t nargs
_PyArg_BadArgument("bindtextdomain", "argument 1", "str", args[0]);
goto exit;
}
- domain = PyUnicode_AsUTF8(args[0]);
+ Py_ssize_t domain_length;
+ domain = PyUnicode_AsUTF8AndSize(args[0], &domain_length);
if (domain == NULL) {
goto exit;
}
+ if (strlen(domain) != (size_t)domain_length) {
+ PyErr_SetString(PyExc_ValueError, "embedded null character");
+ goto exit;
+ }
dirname_obj = args[1];
return_value = _locale_bindtextdomain_impl(module, domain, dirname_obj);
@@ -463,18 +503,28 @@ _locale_bind_textdomain_codeset(PyObject *module, PyObject *const *args, Py_ssiz
_PyArg_BadArgument("bind_textdomain_codeset", "argument 1", "str", args[0]);
goto exit;
}
- domain = PyUnicode_AsUTF8(args[0]);
+ Py_ssize_t domain_length;
+ domain = PyUnicode_AsUTF8AndSize(args[0], &domain_length);
if (domain == NULL) {
goto exit;
}
+ if (strlen(domain) != (size_t)domain_length) {
+ PyErr_SetString(PyExc_ValueError, "embedded null character");
+ goto exit;
+ }
if (args[1] == Py_None) {
codeset = NULL;
}
else if (PyUnicode_Check(args[1])) {
- codeset = PyUnicode_AsUTF8(args[1]);
+ Py_ssize_t codeset_length;
+ codeset = PyUnicode_AsUTF8AndSize(args[1], &codeset_length);
if (codeset == NULL) {
goto exit;
}
+ if (strlen(codeset) != (size_t)codeset_length) {
+ PyErr_SetString(PyExc_ValueError, "embedded null character");
+ goto exit;
+ }
}
else {
_PyArg_BadArgument("bind_textdomain_codeset", "argument 2", "str or None", args[1]);
@@ -545,4 +595,4 @@ _locale_getencoding(PyObject *module, PyObject *Py_UNUSED(ignored))
#ifndef _LOCALE_BIND_TEXTDOMAIN_CODESET_METHODDEF
#define _LOCALE_BIND_TEXTDOMAIN_CODESET_METHODDEF
#endif /* !defined(_LOCALE_BIND_TEXTDOMAIN_CODESET_METHODDEF) */
-/*[clinic end generated code: output=14a4bffed066ebb3 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=034a3c219466d207 input=a9049054013a1b77]*/