]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-111089: Revert PyUnicode_AsUTF8() changes (#111833)
authorVictor Stinner <vstinner@python.org>
Tue, 7 Nov 2023 22:36:13 +0000 (23:36 +0100)
committerGitHub <noreply@github.com>
Tue, 7 Nov 2023 22:36:13 +0000 (22:36 +0000)
* 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.

50 files changed:
Doc/c-api/unicode.rst
Doc/data/stable_abi.dat
Doc/whatsnew/3.13.rst
Include/cpython/unicodeobject.h
Include/unicodeobject.h
Lib/test/test_capi/test_unicode.py
Lib/test/test_stable_abi_ctypes.py
Misc/NEWS.d/next/C API/2023-10-20-01-42-43.gh-issue-111089.VIrd5q.rst [deleted file]
Misc/NEWS.d/next/C API/2023-10-20-18-07-24.gh-issue-111089.RxkyrQ.rst [deleted file]
Misc/stable_abi.toml
Modules/_io/clinic/_iomodule.c.h
Modules/_io/clinic/fileio.c.h
Modules/_io/clinic/textio.c.h
Modules/_io/clinic/winconsoleio.c.h
Modules/_multiprocessing/clinic/multiprocessing.c.h
Modules/_multiprocessing/clinic/semaphore.c.h
Modules/_multiprocessing/posixshmem.c
Modules/_sqlite/clinic/connection.c.h
Modules/_sqlite/clinic/cursor.c.h
Modules/_sqlite/clinic/module.c.h
Modules/_sqlite/connection.c
Modules/_testcapi/clinic/exceptions.c.h
Modules/cjkcodecs/clinic/multibytecodec.c.h
Modules/clinic/_codecsmodule.c.h
Modules/clinic/_cursesmodule.c.h
Modules/clinic/_dbmmodule.c.h
Modules/clinic/_elementtree.c.h
Modules/clinic/_gdbmmodule.c.h
Modules/clinic/_hashopenssl.c.h
Modules/clinic/_localemodule.c.h
Modules/clinic/_pickle.c.h
Modules/clinic/_ssl.c.h
Modules/clinic/_testclinic.c.h
Modules/clinic/_tkinter.c.h
Modules/clinic/posixmodule.c.h
Modules/clinic/pyexpat.c.h
Modules/clinic/symtablemodule.c.h
Objects/clinic/bytearrayobject.c.h
Objects/clinic/bytesobject.c.h
Objects/clinic/floatobject.c.h
Objects/clinic/memoryobject.c.h
Objects/clinic/unicodeobject.c.h
Objects/typeobject.c
Objects/unicodeobject.c
PC/python3dll.c
Python/clinic/Python-tokenize.c.h
Python/clinic/bltinmodule.c.h
Python/clinic/sysmodule.c.h
Python/getargs.c
Tools/clinic/clinic.py

index 5fa37963e07eff7c7c138e31f3bcab6ea422bf56..e654412965a727db76cbdff89492d593c8f884b2 100644 (file)
@@ -992,19 +992,11 @@ These are the UTF-8 codec APIs:
 
    As :c:func:`PyUnicode_AsUTF8AndSize`, but does not store the size.
 
-   Raise an exception if the *unicode* string contains embedded null
-   characters. To accept embedded null characters and truncate on purpose
-   at the first null byte, ``PyUnicode_AsUTF8AndSize(unicode, NULL)`` can be
-   used instead.
-
    .. versionadded:: 3.3
 
    .. versionchanged:: 3.7
       The return type is now ``const char *`` rather of ``char *``.
 
-   .. versionchanged:: 3.13
-      Raise an exception if the string contains embedded null characters.
-
 
 UTF-32 Codecs
 """""""""""""
index 52d6d967d663270bd27ce5c530fa043f4959fed2..811b1bd84d24174e068ec489cc16c4a24758c5e8 100644 (file)
@@ -726,7 +726,6 @@ function,PyUnicode_AsUCS4,3.7,,
 function,PyUnicode_AsUCS4Copy,3.7,,
 function,PyUnicode_AsUTF16String,3.2,,
 function,PyUnicode_AsUTF32String,3.2,,
-function,PyUnicode_AsUTF8,3.13,,
 function,PyUnicode_AsUTF8AndSize,3.10,,
 function,PyUnicode_AsUTF8String,3.2,,
 function,PyUnicode_AsUnicodeEscapeString,3.2,,
index 84d50a68eace4b9fe1c890777bb603ec05a63d72..291e276dc67ce09b9ab76deb4d19241628456bf0 100644 (file)
@@ -1149,9 +1149,6 @@ New Features
   :c:func:`PyErr_WriteUnraisable`, but allow to customize the warning mesage.
   (Contributed by Serhiy Storchaka in :gh:`108082`.)
 
-* Add :c:func:`PyUnicode_AsUTF8` function to the limited C API.
-  (Contributed by Victor Stinner in :gh:`111089`.)
-
 
 Porting to Python 3.13
 ----------------------
@@ -1222,12 +1219,6 @@ Porting to Python 3.13
   Note that ``Py_TRASHCAN_BEGIN`` has a second argument which
   should be the deallocation function it is in.
 
-* The :c:func:`PyUnicode_AsUTF8` function now raises an exception if the string
-  contains embedded null characters. To accept embedded null characters and
-  truncate on purpose at the first null byte,
-  ``PyUnicode_AsUTF8AndSize(unicode, NULL)`` can be used instead.
-  (Contributed by Victor Stinner in :gh:`111089`.)
-
 * On Windows, ``Python.h`` no longer includes the ``<stddef.h>`` standard
   header file. If needed, it should now be included explicitly. For example, it
   provides ``offsetof()`` function, and ``size_t`` and ``ptrdiff_t`` types.
index d200fa0622cef590ca02abd465a9d102326a5385..cd56a6a74acf51d1633dfe2d08d42e82e83a33d2 100644 (file)
@@ -440,6 +440,22 @@ PyAPI_FUNC(PyObject*) PyUnicode_FromKindAndData(
     const void *buffer,
     Py_ssize_t size);
 
+/* --- Manage the default encoding ---------------------------------------- */
+
+/* Returns a pointer to the default encoding (UTF-8) of the
+   Unicode object unicode.
+
+   Like PyUnicode_AsUTF8AndSize(), this also caches the UTF-8 representation
+   in the unicodeobject.
+
+   _PyUnicode_AsString is a #define for PyUnicode_AsUTF8 to
+   support the previous internal function with the same behaviour.
+
+   Use of this API is DEPRECATED since no size information can be
+   extracted from the returned data.
+*/
+
+PyAPI_FUNC(const char *) PyUnicode_AsUTF8(PyObject *unicode);
 
 /* === Characters Type APIs =============================================== */
 
index ee7b769ce5a6fc2d194f1229798c6daf20f60702..dee00715b3c51d576da7bfbcd84ae362f5f14a0b 100644 (file)
@@ -443,25 +443,17 @@ PyAPI_FUNC(PyObject*) PyUnicode_AsUTF8String(
     PyObject *unicode           /* Unicode object */
     );
 
-// Returns a pointer to the UTF-8 encoding of the Unicode object unicode.
-//
-// Raise an exception if the string contains embedded null characters.
-// Use PyUnicode_AsUTF8AndSize() to accept embedded null characters.
-//
-// This function caches the UTF-8 encoded string in the Unicode object
-// and subsequent calls will return the same string. The memory is released
-// when the Unicode object is deallocated.
-PyAPI_FUNC(const char *) PyUnicode_AsUTF8(PyObject *unicode);
-
-// Returns a pointer to the UTF-8 encoding of the
-// Unicode object unicode and the size of the encoded representation
-// in bytes stored in `*size` (if size is not NULL).
-//
-// On error, `*size` is set to 0 (if size is not NULL).
-//
-// This function caches the UTF-8 encoded string in the Unicode object
-// and subsequent calls will return the same string. The memory is released
-// when the Unicode object is deallocated.
+/* Returns a pointer to the default encoding (UTF-8) of the
+   Unicode object unicode and the size of the encoded representation
+   in bytes stored in *size.
+
+   In case of an error, no *size is set.
+
+   This function caches the UTF-8 encoded string in the unicodeobject
+   and subsequent calls will return the same string.  The memory is released
+   when the unicodeobject is deallocated.
+*/
+
 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030A0000
 PyAPI_FUNC(const char *) PyUnicode_AsUTF8AndSize(
     PyObject *unicode,
index d8537244b395558655aea940dad9ba33427e2a8c..bb6161abf4da81db0b983fe4deb3aac56a0d6789 100644 (file)
@@ -914,10 +914,7 @@ class CAPITest(unittest.TestCase):
         self.assertEqual(unicode_asutf8('abc', 4), b'abc\0')
         self.assertEqual(unicode_asutf8('абв', 7), b'\xd0\xb0\xd0\xb1\xd0\xb2\0')
         self.assertEqual(unicode_asutf8('\U0001f600', 5), b'\xf0\x9f\x98\x80\0')
-
-        # disallow embedded null characters
-        self.assertRaises(ValueError, unicode_asutf8, 'abc\0', 0)
-        self.assertRaises(ValueError, unicode_asutf8, 'abc\0def', 0)
+        self.assertEqual(unicode_asutf8('abc\0def', 8), b'abc\0def\0')
 
         self.assertRaises(UnicodeEncodeError, unicode_asutf8, '\ud8ff', 0)
         self.assertRaises(TypeError, unicode_asutf8, b'abc', 0)
index 85a63c44b494316e04bd65a7112944f4cc3d6b62..4976ac3642bbe4664dc408f2c6c820cf0f512ccd 100644 (file)
@@ -745,7 +745,6 @@ SYMBOL_NAMES = (
     "PyUnicode_AsUCS4Copy",
     "PyUnicode_AsUTF16String",
     "PyUnicode_AsUTF32String",
-    "PyUnicode_AsUTF8",
     "PyUnicode_AsUTF8AndSize",
     "PyUnicode_AsUTF8String",
     "PyUnicode_AsUnicodeEscapeString",
diff --git a/Misc/NEWS.d/next/C API/2023-10-20-01-42-43.gh-issue-111089.VIrd5q.rst b/Misc/NEWS.d/next/C API/2023-10-20-01-42-43.gh-issue-111089.VIrd5q.rst
deleted file mode 100644 (file)
index 2008dd5..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-The :c:func:`PyUnicode_AsUTF8` function now raises an exception if the
-string contains embedded null characters. Patch by Victor Stinner.
diff --git a/Misc/NEWS.d/next/C API/2023-10-20-18-07-24.gh-issue-111089.RxkyrQ.rst b/Misc/NEWS.d/next/C API/2023-10-20-18-07-24.gh-issue-111089.RxkyrQ.rst
deleted file mode 100644 (file)
index fe32e06..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-Add :c:func:`PyUnicode_AsUTF8` function to the limited C API. Patch by
-Victor Stinner.
index b55bb599d71dcc1080597c38493e233d55891130..22b25dd0ec141fdc60b6d905a974fbe2e55756e8 100644 (file)
     added = '3.13'
 [function.PySys_AuditTuple]
     added = '3.13'
-[function.PyUnicode_AsUTF8]
-    added = '3.13'
 [function._Py_SetRefcnt]
     added = '3.13'
     abi_only = true
index 68a8a20514027dc4e9d2336f348041cb6ea4bd0b..112408a95df036eccdf4c2b59e6050fadc048a6b 100644 (file)
@@ -188,10 +188,15 @@ _io_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw
             _PyArg_BadArgument("open", "argument 'mode'", "str", args[1]);
             goto exit;
         }
-        mode = PyUnicode_AsUTF8(args[1]);
+        Py_ssize_t mode_length;
+        mode = PyUnicode_AsUTF8AndSize(args[1], &mode_length);
         if (mode == NULL) {
             goto exit;
         }
+        if (strlen(mode) != (size_t)mode_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
         if (!--noptargs) {
             goto skip_optional_pos;
         }
@@ -210,10 +215,15 @@ _io_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw
             encoding = NULL;
         }
         else if (PyUnicode_Check(args[3])) {
-            encoding = PyUnicode_AsUTF8(args[3]);
+            Py_ssize_t encoding_length;
+            encoding = PyUnicode_AsUTF8AndSize(args[3], &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("open", "argument 'encoding'", "str or None", args[3]);
@@ -228,10 +238,15 @@ _io_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw
             errors = NULL;
         }
         else if (PyUnicode_Check(args[4])) {
-            errors = PyUnicode_AsUTF8(args[4]);
+            Py_ssize_t errors_length;
+            errors = PyUnicode_AsUTF8AndSize(args[4], &errors_length);
             if (errors == NULL) {
                 goto exit;
             }
+            if (strlen(errors) != (size_t)errors_length) {
+                PyErr_SetString(PyExc_ValueError, "embedded null character");
+                goto exit;
+            }
         }
         else {
             _PyArg_BadArgument("open", "argument 'errors'", "str or None", args[4]);
@@ -246,10 +261,15 @@ _io_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw
             newline = NULL;
         }
         else if (PyUnicode_Check(args[5])) {
-            newline = PyUnicode_AsUTF8(args[5]);
+            Py_ssize_t newline_length;
+            newline = PyUnicode_AsUTF8AndSize(args[5], &newline_length);
             if (newline == NULL) {
                 goto exit;
             }
+            if (strlen(newline) != (size_t)newline_length) {
+                PyErr_SetString(PyExc_ValueError, "embedded null character");
+                goto exit;
+            }
         }
         else {
             _PyArg_BadArgument("open", "argument 'newline'", "str or None", args[5]);
@@ -384,4 +404,4 @@ _io_open_code(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObjec
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=feb173d5f2bfb98a input=a9049054013a1b77]*/
+/*[clinic end generated code: output=5d60f4e778a600a4 input=a9049054013a1b77]*/
index 6f5d660affd569c6a63199d683ae45b0ba6eac78..cf3ba28b066cf7f5947d96262539e15b0942d77a 100644 (file)
@@ -107,10 +107,15 @@ _io_FileIO___init__(PyObject *self, PyObject *args, PyObject *kwargs)
             _PyArg_BadArgument("FileIO", "argument 'mode'", "str", fastargs[1]);
             goto exit;
         }
-        mode = PyUnicode_AsUTF8(fastargs[1]);
+        Py_ssize_t mode_length;
+        mode = PyUnicode_AsUTF8AndSize(fastargs[1], &mode_length);
         if (mode == NULL) {
             goto exit;
         }
+        if (strlen(mode) != (size_t)mode_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
         if (!--noptargs) {
             goto skip_optional_pos;
         }
@@ -523,4 +528,4 @@ _io_FileIO_isatty(fileio *self, PyObject *Py_UNUSED(ignored))
 #ifndef _IO_FILEIO_TRUNCATE_METHODDEF
     #define _IO_FILEIO_TRUNCATE_METHODDEF
 #endif /* !defined(_IO_FILEIO_TRUNCATE_METHODDEF) */
-/*[clinic end generated code: output=27cff9d0a618edb6 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=1c0f4a36f76b0c6a input=a9049054013a1b77]*/
index 25c301ecdb6dab81c7904454fb2f8fa1be410fa6..b24a1669f9b34417779e49326665ae2639b06a48 100644 (file)
@@ -185,10 +185,15 @@ _io__TextIOBase_write(PyObject *self, PyTypeObject *cls, PyObject *const *args,
         _PyArg_BadArgument("write", "argument 1", "str", args[0]);
         goto exit;
     }
-    s = PyUnicode_AsUTF8(args[0]);
+    Py_ssize_t s_length;
+    s = PyUnicode_AsUTF8AndSize(args[0], &s_length);
     if (s == NULL) {
         goto exit;
     }
+    if (strlen(s) != (size_t)s_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     return_value = _io__TextIOBase_write_impl(self, cls, s);
 
 exit:
@@ -470,10 +475,15 @@ _io_TextIOWrapper___init__(PyObject *self, PyObject *args, PyObject *kwargs)
             encoding = NULL;
         }
         else if (PyUnicode_Check(fastargs[1])) {
-            encoding = PyUnicode_AsUTF8(fastargs[1]);
+            Py_ssize_t encoding_length;
+            encoding = PyUnicode_AsUTF8AndSize(fastargs[1], &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("TextIOWrapper", "argument 'encoding'", "str or None", fastargs[1]);
@@ -494,10 +504,15 @@ _io_TextIOWrapper___init__(PyObject *self, PyObject *args, PyObject *kwargs)
             newline = NULL;
         }
         else if (PyUnicode_Check(fastargs[3])) {
-            newline = PyUnicode_AsUTF8(fastargs[3]);
+            Py_ssize_t newline_length;
+            newline = PyUnicode_AsUTF8AndSize(fastargs[3], &newline_length);
             if (newline == NULL) {
                 goto exit;
             }
+            if (strlen(newline) != (size_t)newline_length) {
+                PyErr_SetString(PyExc_ValueError, "embedded null character");
+                goto exit;
+            }
         }
         else {
             _PyArg_BadArgument("TextIOWrapper", "argument 'newline'", "str or None", fastargs[3]);
@@ -965,4 +980,4 @@ _io_TextIOWrapper_close(textio *self, PyObject *Py_UNUSED(ignored))
 {
     return _io_TextIOWrapper_close_impl(self);
 }
-/*[clinic end generated code: output=c9ffb48a5278cbd4 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=e58ce89b7354e77a input=a9049054013a1b77]*/
index 8609fc9ede95feba68fcddd1a26b4cfe6bc35adf..6cab295c44611d44b86d23dca4854ac1a0cec735 100644 (file)
@@ -106,10 +106,15 @@ _io__WindowsConsoleIO___init__(PyObject *self, PyObject *args, PyObject *kwargs)
             _PyArg_BadArgument("_WindowsConsoleIO", "argument 'mode'", "str", fastargs[1]);
             goto exit;
         }
-        mode = PyUnicode_AsUTF8(fastargs[1]);
+        Py_ssize_t mode_length;
+        mode = PyUnicode_AsUTF8AndSize(fastargs[1], &mode_length);
         if (mode == NULL) {
             goto exit;
         }
+        if (strlen(mode) != (size_t)mode_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
         if (!--noptargs) {
             goto skip_optional_pos;
         }
@@ -452,4 +457,4 @@ _io__WindowsConsoleIO_isatty(winconsoleio *self, PyObject *Py_UNUSED(ignored))
 #ifndef _IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF
     #define _IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF
 #endif /* !defined(_IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF) */
-/*[clinic end generated code: output=76408dd67894bc9c input=a9049054013a1b77]*/
+/*[clinic end generated code: output=04108fc26b187386 input=a9049054013a1b77]*/
index 9133d5d8bb04fd31765a8a000d83cf07f65173a1..6d4f5c2afcfd398d4ba21fff2162250c301ec166 100644 (file)
@@ -138,10 +138,15 @@ _multiprocessing_sem_unlink(PyObject *module, PyObject *arg)
         _PyArg_BadArgument("sem_unlink", "argument", "str", arg);
         goto exit;
     }
-    name = PyUnicode_AsUTF8(arg);
+    Py_ssize_t name_length;
+    name = PyUnicode_AsUTF8AndSize(arg, &name_length);
     if (name == NULL) {
         goto exit;
     }
+    if (strlen(name) != (size_t)name_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     return_value = _multiprocessing_sem_unlink_impl(module, name);
 
 exit:
@@ -159,4 +164,4 @@ exit:
 #ifndef _MULTIPROCESSING_SEND_METHODDEF
     #define _MULTIPROCESSING_SEND_METHODDEF
 #endif /* !defined(_MULTIPROCESSING_SEND_METHODDEF) */
-/*[clinic end generated code: output=c6735cbc59b6f324 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=73b4cb8428d816da input=a9049054013a1b77]*/
index ae340c2f57af202cfe76f975f05da8b788e590ec..7c855113113c20e771e5de948b53e84614b4e42c 100644 (file)
@@ -266,10 +266,15 @@ _multiprocessing_SemLock(PyTypeObject *type, PyObject *args, PyObject *kwargs)
         _PyArg_BadArgument("SemLock", "argument 'name'", "str", fastargs[3]);
         goto exit;
     }
-    name = PyUnicode_AsUTF8(fastargs[3]);
+    Py_ssize_t name_length;
+    name = PyUnicode_AsUTF8AndSize(fastargs[3], &name_length);
     if (name == NULL) {
         goto exit;
     }
+    if (strlen(name) != (size_t)name_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     unlink = PyObject_IsTrue(fastargs[4]);
     if (unlink < 0) {
         goto exit;
@@ -537,4 +542,4 @@ exit:
 #ifndef _MULTIPROCESSING_SEMLOCK___EXIT___METHODDEF
     #define _MULTIPROCESSING_SEMLOCK___EXIT___METHODDEF
 #endif /* !defined(_MULTIPROCESSING_SEMLOCK___EXIT___METHODDEF) */
-/*[clinic end generated code: output=fd94dc907e6ab57f input=a9049054013a1b77]*/
+/*[clinic end generated code: output=d57992037e6770b6 input=a9049054013a1b77]*/
index b1f776cbbeca3f94b29ef880b94870fced825765..cd08a9fedc057849af1dbd75677771cdffb22c2b 100644 (file)
@@ -48,7 +48,7 @@ _posixshmem_shm_open_impl(PyObject *module, PyObject *path, int flags,
 {
     int fd;
     int async_err = 0;
-    const char *name = PyUnicode_AsUTF8(path);
+    const char *name = PyUnicode_AsUTF8AndSize(path, NULL);
     if (name == NULL) {
         return -1;
     }
@@ -87,7 +87,7 @@ _posixshmem_shm_unlink_impl(PyObject *module, PyObject *path)
 {
     int rv;
     int async_err = 0;
-    const char *name = PyUnicode_AsUTF8(path);
+    const char *name = PyUnicode_AsUTF8AndSize(path, NULL);
     if (name == NULL) {
         return NULL;
     }
index 8e1a57415c2bd9b04244323310699c3fa386e011..db5eb77891e52e53cf38b54980cc0527381501ab 100644 (file)
@@ -297,18 +297,28 @@ blobopen(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyO
         _PyArg_BadArgument("blobopen", "argument 1", "str", args[0]);
         goto exit;
     }
-    table = PyUnicode_AsUTF8(args[0]);
+    Py_ssize_t table_length;
+    table = PyUnicode_AsUTF8AndSize(args[0], &table_length);
     if (table == NULL) {
         goto exit;
     }
+    if (strlen(table) != (size_t)table_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     if (!PyUnicode_Check(args[1])) {
         _PyArg_BadArgument("blobopen", "argument 2", "str", args[1]);
         goto exit;
     }
-    col = PyUnicode_AsUTF8(args[1]);
+    Py_ssize_t col_length;
+    col = PyUnicode_AsUTF8AndSize(args[1], &col_length);
     if (col == NULL) {
         goto exit;
     }
+    if (strlen(col) != (size_t)col_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     if (!sqlite3_int64_converter(args[2], &row)) {
         goto exit;
     }
@@ -328,10 +338,15 @@ blobopen(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyO
         _PyArg_BadArgument("blobopen", "argument 'name'", "str", args[4]);
         goto exit;
     }
-    name = PyUnicode_AsUTF8(args[4]);
+    Py_ssize_t name_length;
+    name = PyUnicode_AsUTF8AndSize(args[4], &name_length);
     if (name == NULL) {
         goto exit;
     }
+    if (strlen(name) != (size_t)name_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
 skip_optional_kwonly:
     return_value = blobopen_impl(self, table, col, row, readonly, name);
 
@@ -484,10 +499,15 @@ pysqlite_connection_create_function(pysqlite_Connection *self, PyTypeObject *cls
         _PyArg_BadArgument("create_function", "argument 'name'", "str", args[0]);
         goto exit;
     }
-    name = PyUnicode_AsUTF8(args[0]);
+    Py_ssize_t name_length;
+    name = PyUnicode_AsUTF8AndSize(args[0], &name_length);
     if (name == NULL) {
         goto exit;
     }
+    if (strlen(name) != (size_t)name_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     narg = PyLong_AsInt(args[1]);
     if (narg == -1 && PyErr_Occurred()) {
         goto exit;
@@ -562,10 +582,15 @@ create_window_function(pysqlite_Connection *self, PyTypeObject *cls, PyObject *c
         _PyArg_BadArgument("create_window_function", "argument 1", "str", args[0]);
         goto exit;
     }
-    name = PyUnicode_AsUTF8(args[0]);
+    Py_ssize_t name_length;
+    name = PyUnicode_AsUTF8AndSize(args[0], &name_length);
     if (name == NULL) {
         goto exit;
     }
+    if (strlen(name) != (size_t)name_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     num_params = PyLong_AsInt(args[1]);
     if (num_params == -1 && PyErr_Occurred()) {
         goto exit;
@@ -663,10 +688,15 @@ pysqlite_connection_create_aggregate(pysqlite_Connection *self, PyTypeObject *cl
         _PyArg_BadArgument("create_aggregate", "argument 'name'", "str", args[0]);
         goto exit;
     }
-    name = PyUnicode_AsUTF8(args[0]);
+    Py_ssize_t name_length;
+    name = PyUnicode_AsUTF8AndSize(args[0], &name_length);
     if (name == NULL) {
         goto exit;
     }
+    if (strlen(name) != (size_t)name_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     n_arg = PyLong_AsInt(args[1]);
     if (n_arg == -1 && PyErr_Occurred()) {
         goto exit;
@@ -1033,10 +1063,15 @@ pysqlite_connection_load_extension(pysqlite_Connection *self, PyObject *const *a
         _PyArg_BadArgument("load_extension", "argument 1", "str", args[0]);
         goto exit;
     }
-    extension_name = PyUnicode_AsUTF8(args[0]);
+    Py_ssize_t extension_name_length;
+    extension_name = PyUnicode_AsUTF8AndSize(args[0], &extension_name_length);
     if (extension_name == NULL) {
         goto exit;
     }
+    if (strlen(extension_name) != (size_t)extension_name_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     if (!noptargs) {
         goto skip_optional_kwonly;
     }
@@ -1044,10 +1079,15 @@ pysqlite_connection_load_extension(pysqlite_Connection *self, PyObject *const *a
         entrypoint = NULL;
     }
     else if (PyUnicode_Check(args[1])) {
-        entrypoint = PyUnicode_AsUTF8(args[1]);
+        Py_ssize_t entrypoint_length;
+        entrypoint = PyUnicode_AsUTF8AndSize(args[1], &entrypoint_length);
         if (entrypoint == NULL) {
             goto exit;
         }
+        if (strlen(entrypoint) != (size_t)entrypoint_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
     }
     else {
         _PyArg_BadArgument("load_extension", "argument 'entrypoint'", "str or None", args[1]);
@@ -1266,10 +1306,15 @@ pysqlite_connection_backup(pysqlite_Connection *self, PyObject *const *args, Py_
             _PyArg_BadArgument("backup", "argument 'name'", "str", args[3]);
             goto exit;
         }
-        name = PyUnicode_AsUTF8(args[3]);
+        Py_ssize_t name_length;
+        name = PyUnicode_AsUTF8AndSize(args[3], &name_length);
         if (name == NULL) {
             goto exit;
         }
+        if (strlen(name) != (size_t)name_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
         if (!--noptargs) {
             goto skip_optional_kwonly;
         }
@@ -1335,10 +1380,15 @@ pysqlite_connection_create_collation(pysqlite_Connection *self, PyTypeObject *cl
         _PyArg_BadArgument("create_collation", "argument 1", "str", args[0]);
         goto exit;
     }
-    name = PyUnicode_AsUTF8(args[0]);
+    Py_ssize_t name_length;
+    name = PyUnicode_AsUTF8AndSize(args[0], &name_length);
     if (name == NULL) {
         goto exit;
     }
+    if (strlen(name) != (size_t)name_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     callable = args[1];
     return_value = pysqlite_connection_create_collation_impl(self, cls, name, callable);
 
@@ -1412,10 +1462,15 @@ serialize(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, Py
         _PyArg_BadArgument("serialize", "argument 'name'", "str", args[0]);
         goto exit;
     }
-    name = PyUnicode_AsUTF8(args[0]);
+    Py_ssize_t name_length;
+    name = PyUnicode_AsUTF8AndSize(args[0], &name_length);
     if (name == NULL) {
         goto exit;
     }
+    if (strlen(name) != (size_t)name_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
 skip_optional_kwonly:
     return_value = serialize_impl(self, name);
 
@@ -1510,10 +1565,15 @@ deserialize(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs,
         _PyArg_BadArgument("deserialize", "argument 'name'", "str", args[1]);
         goto exit;
     }
-    name = PyUnicode_AsUTF8(args[1]);
+    Py_ssize_t name_length;
+    name = PyUnicode_AsUTF8AndSize(args[1], &name_length);
     if (name == NULL) {
         goto exit;
     }
+    if (strlen(name) != (size_t)name_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
 skip_optional_kwonly:
     return_value = deserialize_impl(self, &data, name);
 
@@ -1758,4 +1818,4 @@ exit:
 #ifndef DESERIALIZE_METHODDEF
     #define DESERIALIZE_METHODDEF
 #endif /* !defined(DESERIALIZE_METHODDEF) */
-/*[clinic end generated code: output=7d2a4d9272f7cb9e input=a9049054013a1b77]*/
+/*[clinic end generated code: output=90b5b9c14261b8d7 input=a9049054013a1b77]*/
index 7a5850312ee789a9a1aeec1eeca82631cf558953..a13e0d0745b58ddd955966ec1690aa9b1d744837 100644 (file)
@@ -135,10 +135,15 @@ pysqlite_cursor_executescript(pysqlite_Cursor *self, PyObject *arg)
         _PyArg_BadArgument("executescript", "argument", "str", arg);
         goto exit;
     }
-    sql_script = PyUnicode_AsUTF8(arg);
+    Py_ssize_t sql_script_length;
+    sql_script = PyUnicode_AsUTF8AndSize(arg, &sql_script_length);
     if (sql_script == NULL) {
         goto exit;
     }
+    if (strlen(sql_script) != (size_t)sql_script_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     return_value = pysqlite_cursor_executescript_impl(self, sql_script);
 
 exit:
@@ -308,4 +313,4 @@ pysqlite_cursor_close(pysqlite_Cursor *self, PyObject *Py_UNUSED(ignored))
 {
     return pysqlite_cursor_close_impl(self);
 }
-/*[clinic end generated code: output=c772882c7df587ea input=a9049054013a1b77]*/
+/*[clinic end generated code: output=a8ce095c3c80cf65 input=a9049054013a1b77]*/
index d3c7ad8b7ca998a14c765aab23f1f56fffd17f7a..529dc4e281e0eb5a5ba01694a7552a5d37cec34e 100644 (file)
@@ -60,10 +60,15 @@ pysqlite_complete_statement(PyObject *module, PyObject *const *args, Py_ssize_t
         _PyArg_BadArgument("complete_statement", "argument 'statement'", "str", args[0]);
         goto exit;
     }
-    statement = PyUnicode_AsUTF8(args[0]);
+    Py_ssize_t statement_length;
+    statement = PyUnicode_AsUTF8AndSize(args[0], &statement_length);
     if (statement == NULL) {
         goto exit;
     }
+    if (strlen(statement) != (size_t)statement_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     return_value = pysqlite_complete_statement_impl(module, statement);
 
 exit:
@@ -203,4 +208,4 @@ skip_optional:
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=19016e67830c19eb input=a9049054013a1b77]*/
+/*[clinic end generated code: output=457ab0fdbb9e1880 input=a9049054013a1b77]*/
index ce46c1e69f31310fd019e8c9ed6a0e72b1c39ed5..319ed0c29c7a9b617c7d91ee4efc988b635df13e 100644 (file)
@@ -76,10 +76,15 @@ isolation_level_converter(PyObject *str_or_none, const char **result)
         *result = NULL;
     }
     else if (PyUnicode_Check(str_or_none)) {
-        const char *str = PyUnicode_AsUTF8(str_or_none);
+        Py_ssize_t sz;
+        const char *str = PyUnicode_AsUTF8AndSize(str_or_none, &sz);
         if (str == NULL) {
             return 0;
         }
+        if (strlen(str) != (size_t)sz) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            return 0;
+        }
 
         const char *level = get_isolation_level(str);
         if (level == NULL) {
index 80c52f48ced7b3425dafd871f02aed31fa32043f..a797444c1a72b985431d069f37cd6559ef6ae69c 100644 (file)
@@ -112,10 +112,15 @@ _testcapi_make_exception_with_doc(PyObject *module, PyObject *const *args, Py_ss
         _PyArg_BadArgument("make_exception_with_doc", "argument 'name'", "str", args[0]);
         goto exit;
     }
-    name = PyUnicode_AsUTF8(args[0]);
+    Py_ssize_t name_length;
+    name = PyUnicode_AsUTF8AndSize(args[0], &name_length);
     if (name == NULL) {
         goto exit;
     }
+    if (strlen(name) != (size_t)name_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     if (!noptargs) {
         goto skip_optional_pos;
     }
@@ -124,10 +129,15 @@ _testcapi_make_exception_with_doc(PyObject *module, PyObject *const *args, Py_ss
             _PyArg_BadArgument("make_exception_with_doc", "argument 'doc'", "str", args[1]);
             goto exit;
         }
-        doc = PyUnicode_AsUTF8(args[1]);
+        Py_ssize_t doc_length;
+        doc = PyUnicode_AsUTF8AndSize(args[1], &doc_length);
         if (doc == NULL) {
             goto exit;
         }
+        if (strlen(doc) != (size_t)doc_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
         if (!--noptargs) {
             goto skip_optional_pos;
         }
@@ -446,4 +456,4 @@ _testcapi_unstable_exc_prep_reraise_star(PyObject *module, PyObject *const *args
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=6f2b4f773e0ae755 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=0b11ef105030a48e input=a9049054013a1b77]*/
index fec223930cd48ca45f4e17ad926897e94752684e..305ade17b1f1aa80ebda8440c03b42c2813c41ec 100644 (file)
@@ -73,10 +73,15 @@ _multibytecodec_MultibyteCodec_encode(MultibyteCodecObject *self, PyObject *cons
         errors = NULL;
     }
     else if (PyUnicode_Check(args[1])) {
-        errors = PyUnicode_AsUTF8(args[1]);
+        Py_ssize_t errors_length;
+        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
         if (errors == NULL) {
             goto exit;
         }
+        if (strlen(errors) != (size_t)errors_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
     }
     else {
         _PyArg_BadArgument("encode", "argument 'errors'", "str or None", args[1]);
@@ -156,10 +161,15 @@ _multibytecodec_MultibyteCodec_decode(MultibyteCodecObject *self, PyObject *cons
         errors = NULL;
     }
     else if (PyUnicode_Check(args[1])) {
-        errors = PyUnicode_AsUTF8(args[1]);
+        Py_ssize_t errors_length;
+        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
         if (errors == NULL) {
             goto exit;
         }
+        if (strlen(errors) != (size_t)errors_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
     }
     else {
         _PyArg_BadArgument("decode", "argument 'errors'", "str or None", args[1]);
@@ -672,4 +682,4 @@ PyDoc_STRVAR(_multibytecodec___create_codec__doc__,
 
 #define _MULTIBYTECODEC___CREATE_CODEC_METHODDEF    \
     {"__create_codec", (PyCFunction)_multibytecodec___create_codec, METH_O, _multibytecodec___create_codec__doc__},
-/*[clinic end generated code: output=b35a5c3797e0e54a input=a9049054013a1b77]*/
+/*[clinic end generated code: output=219a363662d2fbff input=a9049054013a1b77]*/
index bf17596274baf29e73d54c194db42fa69c8dea37..12fea806ab52093bf9bcfb71d73f60a8c916c36c 100644 (file)
@@ -54,10 +54,15 @@ _codecs_lookup(PyObject *module, PyObject *arg)
         _PyArg_BadArgument("lookup", "argument", "str", arg);
         goto exit;
     }
-    encoding = PyUnicode_AsUTF8(arg);
+    Py_ssize_t encoding_length;
+    encoding = PyUnicode_AsUTF8AndSize(arg, &encoding_length);
     if (encoding == NULL) {
         goto exit;
     }
+    if (strlen(encoding) != (size_t)encoding_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     return_value = _codecs_lookup_impl(module, encoding);
 
 exit:
@@ -131,10 +136,15 @@ _codecs_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje
             _PyArg_BadArgument("encode", "argument 'encoding'", "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;
+        }
         if (!--noptargs) {
             goto skip_optional_pos;
         }
@@ -143,10 +153,15 @@ _codecs_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje
         _PyArg_BadArgument("encode", "argument 'errors'", "str", args[2]);
         goto exit;
     }
-    errors = PyUnicode_AsUTF8(args[2]);
+    Py_ssize_t errors_length;
+    errors = PyUnicode_AsUTF8AndSize(args[2], &errors_length);
     if (errors == NULL) {
         goto exit;
     }
+    if (strlen(errors) != (size_t)errors_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
 skip_optional_pos:
     return_value = _codecs_encode_impl(module, obj, encoding, errors);
 
@@ -221,10 +236,15 @@ _codecs_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje
             _PyArg_BadArgument("decode", "argument 'encoding'", "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;
+        }
         if (!--noptargs) {
             goto skip_optional_pos;
         }
@@ -233,10 +253,15 @@ _codecs_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje
         _PyArg_BadArgument("decode", "argument 'errors'", "str", args[2]);
         goto exit;
     }
-    errors = PyUnicode_AsUTF8(args[2]);
+    Py_ssize_t errors_length;
+    errors = PyUnicode_AsUTF8AndSize(args[2], &errors_length);
     if (errors == NULL) {
         goto exit;
     }
+    if (strlen(errors) != (size_t)errors_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
 skip_optional_pos:
     return_value = _codecs_decode_impl(module, obj, encoding, errors);
 
@@ -286,10 +311,15 @@ _codecs_escape_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
         errors = NULL;
     }
     else if (PyUnicode_Check(args[1])) {
-        errors = PyUnicode_AsUTF8(args[1]);
+        Py_ssize_t errors_length;
+        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
         if (errors == NULL) {
             goto exit;
         }
+        if (strlen(errors) != (size_t)errors_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
     }
     else {
         _PyArg_BadArgument("escape_decode", "argument 2", "str or None", args[1]);
@@ -341,10 +371,15 @@ _codecs_escape_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
         errors = NULL;
     }
     else if (PyUnicode_Check(args[1])) {
-        errors = PyUnicode_AsUTF8(args[1]);
+        Py_ssize_t errors_length;
+        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
         if (errors == NULL) {
             goto exit;
         }
+        if (strlen(errors) != (size_t)errors_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
     }
     else {
         _PyArg_BadArgument("escape_encode", "argument 2", "str or None", args[1]);
@@ -390,10 +425,15 @@ _codecs_utf_7_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
         errors = NULL;
     }
     else if (PyUnicode_Check(args[1])) {
-        errors = PyUnicode_AsUTF8(args[1]);
+        Py_ssize_t errors_length;
+        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
         if (errors == NULL) {
             goto exit;
         }
+        if (strlen(errors) != (size_t)errors_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
     }
     else {
         _PyArg_BadArgument("utf_7_decode", "argument 2", "str or None", args[1]);
@@ -451,10 +491,15 @@ _codecs_utf_8_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
         errors = NULL;
     }
     else if (PyUnicode_Check(args[1])) {
-        errors = PyUnicode_AsUTF8(args[1]);
+        Py_ssize_t errors_length;
+        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
         if (errors == NULL) {
             goto exit;
         }
+        if (strlen(errors) != (size_t)errors_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
     }
     else {
         _PyArg_BadArgument("utf_8_decode", "argument 2", "str or None", args[1]);
@@ -512,10 +557,15 @@ _codecs_utf_16_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
         errors = NULL;
     }
     else if (PyUnicode_Check(args[1])) {
-        errors = PyUnicode_AsUTF8(args[1]);
+        Py_ssize_t errors_length;
+        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
         if (errors == NULL) {
             goto exit;
         }
+        if (strlen(errors) != (size_t)errors_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
     }
     else {
         _PyArg_BadArgument("utf_16_decode", "argument 2", "str or None", args[1]);
@@ -573,10 +623,15 @@ _codecs_utf_16_le_decode(PyObject *module, PyObject *const *args, Py_ssize_t nar
         errors = NULL;
     }
     else if (PyUnicode_Check(args[1])) {
-        errors = PyUnicode_AsUTF8(args[1]);
+        Py_ssize_t errors_length;
+        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
         if (errors == NULL) {
             goto exit;
         }
+        if (strlen(errors) != (size_t)errors_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
     }
     else {
         _PyArg_BadArgument("utf_16_le_decode", "argument 2", "str or None", args[1]);
@@ -634,10 +689,15 @@ _codecs_utf_16_be_decode(PyObject *module, PyObject *const *args, Py_ssize_t nar
         errors = NULL;
     }
     else if (PyUnicode_Check(args[1])) {
-        errors = PyUnicode_AsUTF8(args[1]);
+        Py_ssize_t errors_length;
+        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
         if (errors == NULL) {
             goto exit;
         }
+        if (strlen(errors) != (size_t)errors_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
     }
     else {
         _PyArg_BadArgument("utf_16_be_decode", "argument 2", "str or None", args[1]);
@@ -697,10 +757,15 @@ _codecs_utf_16_ex_decode(PyObject *module, PyObject *const *args, Py_ssize_t nar
         errors = NULL;
     }
     else if (PyUnicode_Check(args[1])) {
-        errors = PyUnicode_AsUTF8(args[1]);
+        Py_ssize_t errors_length;
+        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
         if (errors == NULL) {
             goto exit;
         }
+        if (strlen(errors) != (size_t)errors_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
     }
     else {
         _PyArg_BadArgument("utf_16_ex_decode", "argument 2", "str or None", args[1]);
@@ -765,10 +830,15 @@ _codecs_utf_32_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
         errors = NULL;
     }
     else if (PyUnicode_Check(args[1])) {
-        errors = PyUnicode_AsUTF8(args[1]);
+        Py_ssize_t errors_length;
+        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
         if (errors == NULL) {
             goto exit;
         }
+        if (strlen(errors) != (size_t)errors_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
     }
     else {
         _PyArg_BadArgument("utf_32_decode", "argument 2", "str or None", args[1]);
@@ -826,10 +896,15 @@ _codecs_utf_32_le_decode(PyObject *module, PyObject *const *args, Py_ssize_t nar
         errors = NULL;
     }
     else if (PyUnicode_Check(args[1])) {
-        errors = PyUnicode_AsUTF8(args[1]);
+        Py_ssize_t errors_length;
+        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
         if (errors == NULL) {
             goto exit;
         }
+        if (strlen(errors) != (size_t)errors_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
     }
     else {
         _PyArg_BadArgument("utf_32_le_decode", "argument 2", "str or None", args[1]);
@@ -887,10 +962,15 @@ _codecs_utf_32_be_decode(PyObject *module, PyObject *const *args, Py_ssize_t nar
         errors = NULL;
     }
     else if (PyUnicode_Check(args[1])) {
-        errors = PyUnicode_AsUTF8(args[1]);
+        Py_ssize_t errors_length;
+        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
         if (errors == NULL) {
             goto exit;
         }
+        if (strlen(errors) != (size_t)errors_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
     }
     else {
         _PyArg_BadArgument("utf_32_be_decode", "argument 2", "str or None", args[1]);
@@ -950,10 +1030,15 @@ _codecs_utf_32_ex_decode(PyObject *module, PyObject *const *args, Py_ssize_t nar
         errors = NULL;
     }
     else if (PyUnicode_Check(args[1])) {
-        errors = PyUnicode_AsUTF8(args[1]);
+        Py_ssize_t errors_length;
+        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
         if (errors == NULL) {
             goto exit;
         }
+        if (strlen(errors) != (size_t)errors_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
     }
     else {
         _PyArg_BadArgument("utf_32_ex_decode", "argument 2", "str or None", args[1]);
@@ -1028,10 +1113,15 @@ _codecs_unicode_escape_decode(PyObject *module, PyObject *const *args, Py_ssize_
         errors = NULL;
     }
     else if (PyUnicode_Check(args[1])) {
-        errors = PyUnicode_AsUTF8(args[1]);
+        Py_ssize_t errors_length;
+        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
         if (errors == NULL) {
             goto exit;
         }
+        if (strlen(errors) != (size_t)errors_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
     }
     else {
         _PyArg_BadArgument("unicode_escape_decode", "argument 2", "str or None", args[1]);
@@ -1099,10 +1189,15 @@ _codecs_raw_unicode_escape_decode(PyObject *module, PyObject *const *args, Py_ss
         errors = NULL;
     }
     else if (PyUnicode_Check(args[1])) {
-        errors = PyUnicode_AsUTF8(args[1]);
+        Py_ssize_t errors_length;
+        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
         if (errors == NULL) {
             goto exit;
         }
+        if (strlen(errors) != (size_t)errors_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
     }
     else {
         _PyArg_BadArgument("raw_unicode_escape_decode", "argument 2", "str or None", args[1]);
@@ -1159,10 +1254,15 @@ _codecs_latin_1_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs
         errors = NULL;
     }
     else if (PyUnicode_Check(args[1])) {
-        errors = PyUnicode_AsUTF8(args[1]);
+        Py_ssize_t errors_length;
+        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
         if (errors == NULL) {
             goto exit;
         }
+        if (strlen(errors) != (size_t)errors_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
     }
     else {
         _PyArg_BadArgument("latin_1_decode", "argument 2", "str or None", args[1]);
@@ -1212,10 +1312,15 @@ _codecs_ascii_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
         errors = NULL;
     }
     else if (PyUnicode_Check(args[1])) {
-        errors = PyUnicode_AsUTF8(args[1]);
+        Py_ssize_t errors_length;
+        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
         if (errors == NULL) {
             goto exit;
         }
+        if (strlen(errors) != (size_t)errors_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
     }
     else {
         _PyArg_BadArgument("ascii_decode", "argument 2", "str or None", args[1]);
@@ -1266,10 +1371,15 @@ _codecs_charmap_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs
         errors = NULL;
     }
     else if (PyUnicode_Check(args[1])) {
-        errors = PyUnicode_AsUTF8(args[1]);
+        Py_ssize_t errors_length;
+        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
         if (errors == NULL) {
             goto exit;
         }
+        if (strlen(errors) != (size_t)errors_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
     }
     else {
         _PyArg_BadArgument("charmap_decode", "argument 2", "str or None", args[1]);
@@ -1326,10 +1436,15 @@ _codecs_mbcs_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
         errors = NULL;
     }
     else if (PyUnicode_Check(args[1])) {
-        errors = PyUnicode_AsUTF8(args[1]);
+        Py_ssize_t errors_length;
+        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
         if (errors == NULL) {
             goto exit;
         }
+        if (strlen(errors) != (size_t)errors_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
     }
     else {
         _PyArg_BadArgument("mbcs_decode", "argument 2", "str or None", args[1]);
@@ -1391,10 +1506,15 @@ _codecs_oem_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
         errors = NULL;
     }
     else if (PyUnicode_Check(args[1])) {
-        errors = PyUnicode_AsUTF8(args[1]);
+        Py_ssize_t errors_length;
+        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
         if (errors == NULL) {
             goto exit;
         }
+        if (strlen(errors) != (size_t)errors_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
     }
     else {
         _PyArg_BadArgument("oem_decode", "argument 2", "str or None", args[1]);
@@ -1461,10 +1581,15 @@ _codecs_code_page_decode(PyObject *module, PyObject *const *args, Py_ssize_t nar
         errors = NULL;
     }
     else if (PyUnicode_Check(args[2])) {
-        errors = PyUnicode_AsUTF8(args[2]);
+        Py_ssize_t errors_length;
+        errors = PyUnicode_AsUTF8AndSize(args[2], &errors_length);
         if (errors == NULL) {
             goto exit;
         }
+        if (strlen(errors) != (size_t)errors_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
     }
     else {
         _PyArg_BadArgument("code_page_decode", "argument 3", "str or None", args[2]);
@@ -1533,10 +1658,15 @@ _codecs_readbuffer_encode(PyObject *module, PyObject *const *args, Py_ssize_t na
         errors = NULL;
     }
     else if (PyUnicode_Check(args[1])) {
-        errors = PyUnicode_AsUTF8(args[1]);
+        Py_ssize_t errors_length;
+        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
         if (errors == NULL) {
             goto exit;
         }
+        if (strlen(errors) != (size_t)errors_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
     }
     else {
         _PyArg_BadArgument("readbuffer_encode", "argument 2", "str or None", args[1]);
@@ -1588,10 +1718,15 @@ _codecs_utf_7_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
         errors = NULL;
     }
     else if (PyUnicode_Check(args[1])) {
-        errors = PyUnicode_AsUTF8(args[1]);
+        Py_ssize_t errors_length;
+        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
         if (errors == NULL) {
             goto exit;
         }
+        if (strlen(errors) != (size_t)errors_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
     }
     else {
         _PyArg_BadArgument("utf_7_encode", "argument 2", "str or None", args[1]);
@@ -1638,10 +1773,15 @@ _codecs_utf_8_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
         errors = NULL;
     }
     else if (PyUnicode_Check(args[1])) {
-        errors = PyUnicode_AsUTF8(args[1]);
+        Py_ssize_t errors_length;
+        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
         if (errors == NULL) {
             goto exit;
         }
+        if (strlen(errors) != (size_t)errors_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
     }
     else {
         _PyArg_BadArgument("utf_8_encode", "argument 2", "str or None", args[1]);
@@ -1689,10 +1829,15 @@ _codecs_utf_16_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
         errors = NULL;
     }
     else if (PyUnicode_Check(args[1])) {
-        errors = PyUnicode_AsUTF8(args[1]);
+        Py_ssize_t errors_length;
+        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
         if (errors == NULL) {
             goto exit;
         }
+        if (strlen(errors) != (size_t)errors_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
     }
     else {
         _PyArg_BadArgument("utf_16_encode", "argument 2", "str or None", args[1]);
@@ -1746,10 +1891,15 @@ _codecs_utf_16_le_encode(PyObject *module, PyObject *const *args, Py_ssize_t nar
         errors = NULL;
     }
     else if (PyUnicode_Check(args[1])) {
-        errors = PyUnicode_AsUTF8(args[1]);
+        Py_ssize_t errors_length;
+        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
         if (errors == NULL) {
             goto exit;
         }
+        if (strlen(errors) != (size_t)errors_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
     }
     else {
         _PyArg_BadArgument("utf_16_le_encode", "argument 2", "str or None", args[1]);
@@ -1796,10 +1946,15 @@ _codecs_utf_16_be_encode(PyObject *module, PyObject *const *args, Py_ssize_t nar
         errors = NULL;
     }
     else if (PyUnicode_Check(args[1])) {
-        errors = PyUnicode_AsUTF8(args[1]);
+        Py_ssize_t errors_length;
+        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
         if (errors == NULL) {
             goto exit;
         }
+        if (strlen(errors) != (size_t)errors_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
     }
     else {
         _PyArg_BadArgument("utf_16_be_encode", "argument 2", "str or None", args[1]);
@@ -1847,10 +2002,15 @@ _codecs_utf_32_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
         errors = NULL;
     }
     else if (PyUnicode_Check(args[1])) {
-        errors = PyUnicode_AsUTF8(args[1]);
+        Py_ssize_t errors_length;
+        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
         if (errors == NULL) {
             goto exit;
         }
+        if (strlen(errors) != (size_t)errors_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
     }
     else {
         _PyArg_BadArgument("utf_32_encode", "argument 2", "str or None", args[1]);
@@ -1904,10 +2064,15 @@ _codecs_utf_32_le_encode(PyObject *module, PyObject *const *args, Py_ssize_t nar
         errors = NULL;
     }
     else if (PyUnicode_Check(args[1])) {
-        errors = PyUnicode_AsUTF8(args[1]);
+        Py_ssize_t errors_length;
+        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
         if (errors == NULL) {
             goto exit;
         }
+        if (strlen(errors) != (size_t)errors_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
     }
     else {
         _PyArg_BadArgument("utf_32_le_encode", "argument 2", "str or None", args[1]);
@@ -1954,10 +2119,15 @@ _codecs_utf_32_be_encode(PyObject *module, PyObject *const *args, Py_ssize_t nar
         errors = NULL;
     }
     else if (PyUnicode_Check(args[1])) {
-        errors = PyUnicode_AsUTF8(args[1]);
+        Py_ssize_t errors_length;
+        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
         if (errors == NULL) {
             goto exit;
         }
+        if (strlen(errors) != (size_t)errors_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
     }
     else {
         _PyArg_BadArgument("utf_32_be_encode", "argument 2", "str or None", args[1]);
@@ -2004,10 +2174,15 @@ _codecs_unicode_escape_encode(PyObject *module, PyObject *const *args, Py_ssize_
         errors = NULL;
     }
     else if (PyUnicode_Check(args[1])) {
-        errors = PyUnicode_AsUTF8(args[1]);
+        Py_ssize_t errors_length;
+        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
         if (errors == NULL) {
             goto exit;
         }
+        if (strlen(errors) != (size_t)errors_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
     }
     else {
         _PyArg_BadArgument("unicode_escape_encode", "argument 2", "str or None", args[1]);
@@ -2054,10 +2229,15 @@ _codecs_raw_unicode_escape_encode(PyObject *module, PyObject *const *args, Py_ss
         errors = NULL;
     }
     else if (PyUnicode_Check(args[1])) {
-        errors = PyUnicode_AsUTF8(args[1]);
+        Py_ssize_t errors_length;
+        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
         if (errors == NULL) {
             goto exit;
         }
+        if (strlen(errors) != (size_t)errors_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
     }
     else {
         _PyArg_BadArgument("raw_unicode_escape_encode", "argument 2", "str or None", args[1]);
@@ -2104,10 +2284,15 @@ _codecs_latin_1_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs
         errors = NULL;
     }
     else if (PyUnicode_Check(args[1])) {
-        errors = PyUnicode_AsUTF8(args[1]);
+        Py_ssize_t errors_length;
+        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
         if (errors == NULL) {
             goto exit;
         }
+        if (strlen(errors) != (size_t)errors_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
     }
     else {
         _PyArg_BadArgument("latin_1_encode", "argument 2", "str or None", args[1]);
@@ -2154,10 +2339,15 @@ _codecs_ascii_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
         errors = NULL;
     }
     else if (PyUnicode_Check(args[1])) {
-        errors = PyUnicode_AsUTF8(args[1]);
+        Py_ssize_t errors_length;
+        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
         if (errors == NULL) {
             goto exit;
         }
+        if (strlen(errors) != (size_t)errors_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
     }
     else {
         _PyArg_BadArgument("ascii_encode", "argument 2", "str or None", args[1]);
@@ -2205,10 +2395,15 @@ _codecs_charmap_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs
         errors = NULL;
     }
     else if (PyUnicode_Check(args[1])) {
-        errors = PyUnicode_AsUTF8(args[1]);
+        Py_ssize_t errors_length;
+        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
         if (errors == NULL) {
             goto exit;
         }
+        if (strlen(errors) != (size_t)errors_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
     }
     else {
         _PyArg_BadArgument("charmap_encode", "argument 2", "str or None", args[1]);
@@ -2288,10 +2483,15 @@ _codecs_mbcs_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
         errors = NULL;
     }
     else if (PyUnicode_Check(args[1])) {
-        errors = PyUnicode_AsUTF8(args[1]);
+        Py_ssize_t errors_length;
+        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
         if (errors == NULL) {
             goto exit;
         }
+        if (strlen(errors) != (size_t)errors_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
     }
     else {
         _PyArg_BadArgument("mbcs_encode", "argument 2", "str or None", args[1]);
@@ -2341,10 +2541,15 @@ _codecs_oem_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
         errors = NULL;
     }
     else if (PyUnicode_Check(args[1])) {
-        errors = PyUnicode_AsUTF8(args[1]);
+        Py_ssize_t errors_length;
+        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
         if (errors == NULL) {
             goto exit;
         }
+        if (strlen(errors) != (size_t)errors_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
     }
     else {
         _PyArg_BadArgument("oem_encode", "argument 2", "str or None", args[1]);
@@ -2400,10 +2605,15 @@ _codecs_code_page_encode(PyObject *module, PyObject *const *args, Py_ssize_t nar
         errors = NULL;
     }
     else if (PyUnicode_Check(args[2])) {
-        errors = PyUnicode_AsUTF8(args[2]);
+        Py_ssize_t errors_length;
+        errors = PyUnicode_AsUTF8AndSize(args[2], &errors_length);
         if (errors == NULL) {
             goto exit;
         }
+        if (strlen(errors) != (size_t)errors_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
     }
     else {
         _PyArg_BadArgument("code_page_encode", "argument 3", "str or None", args[2]);
@@ -2449,10 +2659,15 @@ _codecs_register_error(PyObject *module, PyObject *const *args, Py_ssize_t nargs
         _PyArg_BadArgument("register_error", "argument 1", "str", args[0]);
         goto exit;
     }
-    errors = PyUnicode_AsUTF8(args[0]);
+    Py_ssize_t errors_length;
+    errors = PyUnicode_AsUTF8AndSize(args[0], &errors_length);
     if (errors == NULL) {
         goto exit;
     }
+    if (strlen(errors) != (size_t)errors_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     handler = args[1];
     return_value = _codecs_register_error_impl(module, errors, handler);
 
@@ -2485,10 +2700,15 @@ _codecs_lookup_error(PyObject *module, PyObject *arg)
         _PyArg_BadArgument("lookup_error", "argument", "str", arg);
         goto exit;
     }
-    name = PyUnicode_AsUTF8(arg);
+    Py_ssize_t name_length;
+    name = PyUnicode_AsUTF8AndSize(arg, &name_length);
     if (name == NULL) {
         goto exit;
     }
+    if (strlen(name) != (size_t)name_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     return_value = _codecs_lookup_error_impl(module, name);
 
 exit:
@@ -2518,4 +2738,4 @@ exit:
 #ifndef _CODECS_CODE_PAGE_ENCODE_METHODDEF
     #define _CODECS_CODE_PAGE_ENCODE_METHODDEF
 #endif /* !defined(_CODECS_CODE_PAGE_ENCODE_METHODDEF) */
-/*[clinic end generated code: output=5c95a170d813a46f input=a9049054013a1b77]*/
+/*[clinic end generated code: output=d8d9e372f7ccba35 input=a9049054013a1b77]*/
index 409c61578572f951086e19afc2754db643d5d12c..f7e0aaf7b23649fcf88630813e3f96b4dedbb93c 100644 (file)
@@ -2726,10 +2726,15 @@ _curses_setupterm(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyO
             term = NULL;
         }
         else if (PyUnicode_Check(args[0])) {
-            term = PyUnicode_AsUTF8(args[0]);
+            Py_ssize_t term_length;
+            term = PyUnicode_AsUTF8AndSize(args[0], &term_length);
             if (term == NULL) {
                 goto exit;
             }
+            if (strlen(term) != (size_t)term_length) {
+                PyErr_SetString(PyExc_ValueError, "embedded null character");
+                goto exit;
+            }
         }
         else {
             _PyArg_BadArgument("setupterm", "argument 'term'", "str or None", args[0]);
@@ -3921,10 +3926,15 @@ _curses_tigetflag(PyObject *module, PyObject *arg)
         _PyArg_BadArgument("tigetflag", "argument", "str", arg);
         goto exit;
     }
-    capname = PyUnicode_AsUTF8(arg);
+    Py_ssize_t capname_length;
+    capname = PyUnicode_AsUTF8AndSize(arg, &capname_length);
     if (capname == NULL) {
         goto exit;
     }
+    if (strlen(capname) != (size_t)capname_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     return_value = _curses_tigetflag_impl(module, capname);
 
 exit:
@@ -3959,10 +3969,15 @@ _curses_tigetnum(PyObject *module, PyObject *arg)
         _PyArg_BadArgument("tigetnum", "argument", "str", arg);
         goto exit;
     }
-    capname = PyUnicode_AsUTF8(arg);
+    Py_ssize_t capname_length;
+    capname = PyUnicode_AsUTF8AndSize(arg, &capname_length);
     if (capname == NULL) {
         goto exit;
     }
+    if (strlen(capname) != (size_t)capname_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     return_value = _curses_tigetnum_impl(module, capname);
 
 exit:
@@ -3997,10 +4012,15 @@ _curses_tigetstr(PyObject *module, PyObject *arg)
         _PyArg_BadArgument("tigetstr", "argument", "str", arg);
         goto exit;
     }
-    capname = PyUnicode_AsUTF8(arg);
+    Py_ssize_t capname_length;
+    capname = PyUnicode_AsUTF8AndSize(arg, &capname_length);
     if (capname == NULL) {
         goto exit;
     }
+    if (strlen(capname) != (size_t)capname_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     return_value = _curses_tigetstr_impl(module, capname);
 
 exit:
@@ -4298,4 +4318,4 @@ _curses_has_extended_color_support(PyObject *module, PyObject *Py_UNUSED(ignored
 #ifndef _CURSES_USE_DEFAULT_COLORS_METHODDEF
     #define _CURSES_USE_DEFAULT_COLORS_METHODDEF
 #endif /* !defined(_CURSES_USE_DEFAULT_COLORS_METHODDEF) */
-/*[clinic end generated code: output=555e266fc4838612 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=96887782374f070a input=a9049054013a1b77]*/
index 4b4baf8cd49d348a712c3e665b64d6c09f48b388..5a4aba2825e03a60a85f9adb03cc9ae0625700e3 100644 (file)
@@ -196,10 +196,15 @@ dbmopen(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
         _PyArg_BadArgument("open", "argument 2", "str", args[1]);
         goto exit;
     }
-    flags = PyUnicode_AsUTF8(args[1]);
+    Py_ssize_t flags_length;
+    flags = PyUnicode_AsUTF8AndSize(args[1], &flags_length);
     if (flags == NULL) {
         goto exit;
     }
+    if (strlen(flags) != (size_t)flags_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     if (nargs < 3) {
         goto skip_optional;
     }
@@ -213,4 +218,4 @@ skip_optional:
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=48183905532205c2 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=96fdd4bd7bd256c5 input=a9049054013a1b77]*/
index a14b3815e564235d3bdaf083f3fcad2bee8033cb..02375c8a61e73e4bc33d0939c47f979c558d65cf 100644 (file)
@@ -1131,10 +1131,15 @@ _elementtree_XMLParser___init__(PyObject *self, PyObject *args, PyObject *kwargs
         encoding = NULL;
     }
     else if (PyUnicode_Check(fastargs[1])) {
-        encoding = PyUnicode_AsUTF8(fastargs[1]);
+        Py_ssize_t encoding_length;
+        encoding = PyUnicode_AsUTF8AndSize(fastargs[1], &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("XMLParser", "argument 'encoding'", "str or None", fastargs[1]);
@@ -1214,4 +1219,4 @@ skip_optional:
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=399d9d5c9435070b input=a9049054013a1b77]*/
+/*[clinic end generated code: output=8fdaa17d3262800a input=a9049054013a1b77]*/
index ab7288ee22360c9a651e81da563e710ac601935a..c7164e519d0e7deaa80c035d8133119108eb3009 100644 (file)
@@ -318,10 +318,15 @@ dbmopen(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
         _PyArg_BadArgument("open", "argument 2", "str", args[1]);
         goto exit;
     }
-    flags = PyUnicode_AsUTF8(args[1]);
+    Py_ssize_t flags_length;
+    flags = PyUnicode_AsUTF8AndSize(args[1], &flags_length);
     if (flags == NULL) {
         goto exit;
     }
+    if (strlen(flags) != (size_t)flags_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     if (nargs < 3) {
         goto skip_optional;
     }
@@ -335,4 +340,4 @@ skip_optional:
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=725cafd8b2d8cfdb input=a9049054013a1b77]*/
+/*[clinic end generated code: output=c5ee922363d5a81f input=a9049054013a1b77]*/
index e360e98500729b83efc065f50c7bf251281df11b..58650dff288444b9a5f0daa1be34e43d0f1b084d 100644 (file)
@@ -1278,10 +1278,15 @@ pbkdf2_hmac(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject
         _PyArg_BadArgument("pbkdf2_hmac", "argument 'hash_name'", "str", args[0]);
         goto exit;
     }
-    hash_name = PyUnicode_AsUTF8(args[0]);
+    Py_ssize_t hash_name_length;
+    hash_name = PyUnicode_AsUTF8AndSize(args[0], &hash_name_length);
     if (hash_name == NULL) {
         goto exit;
     }
+    if (strlen(hash_name) != (size_t)hash_name_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     if (PyObject_GetBuffer(args[1], &password, PyBUF_SIMPLE) != 0) {
         goto exit;
     }
@@ -1819,4 +1824,4 @@ exit:
 #ifndef _HASHLIB_SCRYPT_METHODDEF
     #define _HASHLIB_SCRYPT_METHODDEF
 #endif /* !defined(_HASHLIB_SCRYPT_METHODDEF) */
-/*[clinic end generated code: output=bc372898eaa3e000 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=b7eddeb3d6ccdeec input=a9049054013a1b77]*/
index 2663b28fa72bd920300cd53f90658268cb27fc79..5e0880b0d0bb4c0c1420f3da7cdc73cac541e1b0 100644 (file)
@@ -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]*/
index 75edfd03e8ca23abd52e30aa6f01832675cc8811..932ace190e60596435611f2eacbd51554fcb81b6 100644 (file)
@@ -466,10 +466,15 @@ _pickle_Unpickler___init__(PyObject *self, PyObject *args, PyObject *kwargs)
             _PyArg_BadArgument("Unpickler", "argument 'encoding'", "str", fastargs[2]);
             goto exit;
         }
-        encoding = PyUnicode_AsUTF8(fastargs[2]);
+        Py_ssize_t encoding_length;
+        encoding = PyUnicode_AsUTF8AndSize(fastargs[2], &encoding_length);
         if (encoding == NULL) {
             goto exit;
         }
+        if (strlen(encoding) != (size_t)encoding_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
         if (!--noptargs) {
             goto skip_optional_kwonly;
         }
@@ -479,10 +484,15 @@ _pickle_Unpickler___init__(PyObject *self, PyObject *args, PyObject *kwargs)
             _PyArg_BadArgument("Unpickler", "argument 'errors'", "str", fastargs[3]);
             goto exit;
         }
-        errors = PyUnicode_AsUTF8(fastargs[3]);
+        Py_ssize_t errors_length;
+        errors = PyUnicode_AsUTF8AndSize(fastargs[3], &errors_length);
         if (errors == NULL) {
             goto exit;
         }
+        if (strlen(errors) != (size_t)errors_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
         if (!--noptargs) {
             goto skip_optional_kwonly;
         }
@@ -860,10 +870,15 @@ _pickle_load(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject
             _PyArg_BadArgument("load", "argument 'encoding'", "str", args[2]);
             goto exit;
         }
-        encoding = PyUnicode_AsUTF8(args[2]);
+        Py_ssize_t encoding_length;
+        encoding = PyUnicode_AsUTF8AndSize(args[2], &encoding_length);
         if (encoding == NULL) {
             goto exit;
         }
+        if (strlen(encoding) != (size_t)encoding_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
         if (!--noptargs) {
             goto skip_optional_kwonly;
         }
@@ -873,10 +888,15 @@ _pickle_load(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject
             _PyArg_BadArgument("load", "argument 'errors'", "str", args[3]);
             goto exit;
         }
-        errors = PyUnicode_AsUTF8(args[3]);
+        Py_ssize_t errors_length;
+        errors = PyUnicode_AsUTF8AndSize(args[3], &errors_length);
         if (errors == NULL) {
             goto exit;
         }
+        if (strlen(errors) != (size_t)errors_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
         if (!--noptargs) {
             goto skip_optional_kwonly;
         }
@@ -976,10 +996,15 @@ _pickle_loads(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObjec
             _PyArg_BadArgument("loads", "argument 'encoding'", "str", args[2]);
             goto exit;
         }
-        encoding = PyUnicode_AsUTF8(args[2]);
+        Py_ssize_t encoding_length;
+        encoding = PyUnicode_AsUTF8AndSize(args[2], &encoding_length);
         if (encoding == NULL) {
             goto exit;
         }
+        if (strlen(encoding) != (size_t)encoding_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
         if (!--noptargs) {
             goto skip_optional_kwonly;
         }
@@ -989,10 +1014,15 @@ _pickle_loads(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObjec
             _PyArg_BadArgument("loads", "argument 'errors'", "str", args[3]);
             goto exit;
         }
-        errors = PyUnicode_AsUTF8(args[3]);
+        Py_ssize_t errors_length;
+        errors = PyUnicode_AsUTF8AndSize(args[3], &errors_length);
         if (errors == NULL) {
             goto exit;
         }
+        if (strlen(errors) != (size_t)errors_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
         if (!--noptargs) {
             goto skip_optional_kwonly;
         }
@@ -1004,4 +1034,4 @@ skip_optional_kwonly:
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=1c675a6680a6b90c input=a9049054013a1b77]*/
+/*[clinic end generated code: output=7f0564b5fb5410a8 input=a9049054013a1b77]*/
index 7aa435f0b8f3cd95dda35a08ca20e2cf350dcd2e..88401b0490a1bbf973b8e094dda772853f96a058 100644 (file)
@@ -391,10 +391,15 @@ _ssl__SSLSocket_get_channel_binding(PySSLSocket *self, PyObject *const *args, Py
         _PyArg_BadArgument("get_channel_binding", "argument 'cb_type'", "str", args[0]);
         goto exit;
     }
-    cb_type = PyUnicode_AsUTF8(args[0]);
+    Py_ssize_t cb_type_length;
+    cb_type = PyUnicode_AsUTF8AndSize(args[0], &cb_type_length);
     if (cb_type == NULL) {
         goto exit;
     }
+    if (strlen(cb_type) != (size_t)cb_type_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
 skip_optional_pos:
     return_value = _ssl__SSLSocket_get_channel_binding_impl(self, cb_type);
 
@@ -468,10 +473,15 @@ _ssl__SSLContext_set_ciphers(PySSLContext *self, PyObject *arg)
         _PyArg_BadArgument("set_ciphers", "argument", "str", arg);
         goto exit;
     }
-    cipherlist = PyUnicode_AsUTF8(arg);
+    Py_ssize_t cipherlist_length;
+    cipherlist = PyUnicode_AsUTF8AndSize(arg, &cipherlist_length);
     if (cipherlist == NULL) {
         goto exit;
     }
+    if (strlen(cipherlist) != (size_t)cipherlist_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     return_value = _ssl__SSLContext_set_ciphers_impl(self, cipherlist);
 
 exit:
@@ -1306,10 +1316,15 @@ _ssl_txt2obj(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject
         _PyArg_BadArgument("txt2obj", "argument 'txt'", "str", args[0]);
         goto exit;
     }
-    txt = PyUnicode_AsUTF8(args[0]);
+    Py_ssize_t txt_length;
+    txt = PyUnicode_AsUTF8AndSize(args[0], &txt_length);
     if (txt == NULL) {
         goto exit;
     }
+    if (strlen(txt) != (size_t)txt_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     if (!noptargs) {
         goto skip_optional_pos;
     }
@@ -1412,10 +1427,15 @@ _ssl_enum_certificates(PyObject *module, PyObject *const *args, Py_ssize_t nargs
         _PyArg_BadArgument("enum_certificates", "argument 'store_name'", "str", args[0]);
         goto exit;
     }
-    store_name = PyUnicode_AsUTF8(args[0]);
+    Py_ssize_t store_name_length;
+    store_name = PyUnicode_AsUTF8AndSize(args[0], &store_name_length);
     if (store_name == NULL) {
         goto exit;
     }
+    if (strlen(store_name) != (size_t)store_name_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     return_value = _ssl_enum_certificates_impl(module, store_name);
 
 exit:
@@ -1483,10 +1503,15 @@ _ssl_enum_crls(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje
         _PyArg_BadArgument("enum_crls", "argument 'store_name'", "str", args[0]);
         goto exit;
     }
-    store_name = PyUnicode_AsUTF8(args[0]);
+    Py_ssize_t store_name_length;
+    store_name = PyUnicode_AsUTF8AndSize(args[0], &store_name_length);
     if (store_name == NULL) {
         goto exit;
     }
+    if (strlen(store_name) != (size_t)store_name_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     return_value = _ssl_enum_crls_impl(module, store_name);
 
 exit:
@@ -1502,4 +1527,4 @@ exit:
 #ifndef _SSL_ENUM_CRLS_METHODDEF
     #define _SSL_ENUM_CRLS_METHODDEF
 #endif /* !defined(_SSL_ENUM_CRLS_METHODDEF) */
-/*[clinic end generated code: output=8350af68e0a56792 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=aa6b0a898b6077fe input=a9049054013a1b77]*/
index df81710364d910e0848ae73d2a22fa0d43b8d0ae..fea30e778381dea09e2a1cf09b17cb63f11d002a 100644 (file)
@@ -2935,10 +2935,15 @@ clone_f1(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw
         _PyArg_BadArgument("clone_f1", "argument 'path'", "str", args[0]);
         goto exit;
     }
-    path = PyUnicode_AsUTF8(args[0]);
+    Py_ssize_t path_length;
+    path = PyUnicode_AsUTF8AndSize(args[0], &path_length);
     if (path == NULL) {
         goto exit;
     }
+    if (strlen(path) != (size_t)path_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     return_value = clone_f1_impl(module, path);
 
 exit:
@@ -2996,10 +3001,15 @@ clone_f2(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw
         _PyArg_BadArgument("clone_f2", "argument 'path'", "str", args[0]);
         goto exit;
     }
-    path = PyUnicode_AsUTF8(args[0]);
+    Py_ssize_t path_length;
+    path = PyUnicode_AsUTF8AndSize(args[0], &path_length);
     if (path == NULL) {
         goto exit;
     }
+    if (strlen(path) != (size_t)path_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     return_value = clone_f2_impl(module, path);
 
 exit:
@@ -3131,4 +3141,4 @@ skip_optional_pos:
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=32dc6ac90757da7a input=a9049054013a1b77]*/
+/*[clinic end generated code: output=90743ac900d60f9f input=a9049054013a1b77]*/
index 1ff3cec568e330139ae1bf9044735f64c3f9e084..188bcc773cfc41cc863c8003219dd921956c362f 100644 (file)
@@ -25,10 +25,15 @@ _tkinter_tkapp_eval(TkappObject *self, PyObject *arg)
         _PyArg_BadArgument("eval", "argument", "str", arg);
         goto exit;
     }
-    script = PyUnicode_AsUTF8(arg);
+    Py_ssize_t script_length;
+    script = PyUnicode_AsUTF8AndSize(arg, &script_length);
     if (script == NULL) {
         goto exit;
     }
+    if (strlen(script) != (size_t)script_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     return_value = _tkinter_tkapp_eval_impl(self, script);
 
 exit:
@@ -56,10 +61,15 @@ _tkinter_tkapp_evalfile(TkappObject *self, PyObject *arg)
         _PyArg_BadArgument("evalfile", "argument", "str", arg);
         goto exit;
     }
-    fileName = PyUnicode_AsUTF8(arg);
+    Py_ssize_t fileName_length;
+    fileName = PyUnicode_AsUTF8AndSize(arg, &fileName_length);
     if (fileName == NULL) {
         goto exit;
     }
+    if (strlen(fileName) != (size_t)fileName_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     return_value = _tkinter_tkapp_evalfile_impl(self, fileName);
 
 exit:
@@ -87,10 +97,15 @@ _tkinter_tkapp_record(TkappObject *self, PyObject *arg)
         _PyArg_BadArgument("record", "argument", "str", arg);
         goto exit;
     }
-    script = PyUnicode_AsUTF8(arg);
+    Py_ssize_t script_length;
+    script = PyUnicode_AsUTF8AndSize(arg, &script_length);
     if (script == NULL) {
         goto exit;
     }
+    if (strlen(script) != (size_t)script_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     return_value = _tkinter_tkapp_record_impl(self, script);
 
 exit:
@@ -118,10 +133,15 @@ _tkinter_tkapp_adderrorinfo(TkappObject *self, PyObject *arg)
         _PyArg_BadArgument("adderrorinfo", "argument", "str", arg);
         goto exit;
     }
-    msg = PyUnicode_AsUTF8(arg);
+    Py_ssize_t msg_length;
+    msg = PyUnicode_AsUTF8AndSize(arg, &msg_length);
     if (msg == NULL) {
         goto exit;
     }
+    if (strlen(msg) != (size_t)msg_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     return_value = _tkinter_tkapp_adderrorinfo_impl(self, msg);
 
 exit:
@@ -173,10 +193,15 @@ _tkinter_tkapp_exprstring(TkappObject *self, PyObject *arg)
         _PyArg_BadArgument("exprstring", "argument", "str", arg);
         goto exit;
     }
-    s = PyUnicode_AsUTF8(arg);
+    Py_ssize_t s_length;
+    s = PyUnicode_AsUTF8AndSize(arg, &s_length);
     if (s == NULL) {
         goto exit;
     }
+    if (strlen(s) != (size_t)s_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     return_value = _tkinter_tkapp_exprstring_impl(self, s);
 
 exit:
@@ -204,10 +229,15 @@ _tkinter_tkapp_exprlong(TkappObject *self, PyObject *arg)
         _PyArg_BadArgument("exprlong", "argument", "str", arg);
         goto exit;
     }
-    s = PyUnicode_AsUTF8(arg);
+    Py_ssize_t s_length;
+    s = PyUnicode_AsUTF8AndSize(arg, &s_length);
     if (s == NULL) {
         goto exit;
     }
+    if (strlen(s) != (size_t)s_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     return_value = _tkinter_tkapp_exprlong_impl(self, s);
 
 exit:
@@ -235,10 +265,15 @@ _tkinter_tkapp_exprdouble(TkappObject *self, PyObject *arg)
         _PyArg_BadArgument("exprdouble", "argument", "str", arg);
         goto exit;
     }
-    s = PyUnicode_AsUTF8(arg);
+    Py_ssize_t s_length;
+    s = PyUnicode_AsUTF8AndSize(arg, &s_length);
     if (s == NULL) {
         goto exit;
     }
+    if (strlen(s) != (size_t)s_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     return_value = _tkinter_tkapp_exprdouble_impl(self, s);
 
 exit:
@@ -266,10 +301,15 @@ _tkinter_tkapp_exprboolean(TkappObject *self, PyObject *arg)
         _PyArg_BadArgument("exprboolean", "argument", "str", arg);
         goto exit;
     }
-    s = PyUnicode_AsUTF8(arg);
+    Py_ssize_t s_length;
+    s = PyUnicode_AsUTF8AndSize(arg, &s_length);
     if (s == NULL) {
         goto exit;
     }
+    if (strlen(s) != (size_t)s_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     return_value = _tkinter_tkapp_exprboolean_impl(self, s);
 
 exit:
@@ -310,10 +350,15 @@ _tkinter_tkapp_createcommand(TkappObject *self, PyObject *const *args, Py_ssize_
         _PyArg_BadArgument("createcommand", "argument 1", "str", args[0]);
         goto exit;
     }
-    name = PyUnicode_AsUTF8(args[0]);
+    Py_ssize_t name_length;
+    name = PyUnicode_AsUTF8AndSize(args[0], &name_length);
     if (name == NULL) {
         goto exit;
     }
+    if (strlen(name) != (size_t)name_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     func = args[1];
     return_value = _tkinter_tkapp_createcommand_impl(self, name, func);
 
@@ -342,10 +387,15 @@ _tkinter_tkapp_deletecommand(TkappObject *self, PyObject *arg)
         _PyArg_BadArgument("deletecommand", "argument", "str", arg);
         goto exit;
     }
-    name = PyUnicode_AsUTF8(arg);
+    Py_ssize_t name_length;
+    name = PyUnicode_AsUTF8AndSize(arg, &name_length);
     if (name == NULL) {
         goto exit;
     }
+    if (strlen(name) != (size_t)name_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     return_value = _tkinter_tkapp_deletecommand_impl(self, name);
 
 exit:
@@ -644,10 +694,15 @@ _tkinter_create(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
         screenName = NULL;
     }
     else if (PyUnicode_Check(args[0])) {
-        screenName = PyUnicode_AsUTF8(args[0]);
+        Py_ssize_t screenName_length;
+        screenName = PyUnicode_AsUTF8AndSize(args[0], &screenName_length);
         if (screenName == NULL) {
             goto exit;
         }
+        if (strlen(screenName) != (size_t)screenName_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
     }
     else {
         _PyArg_BadArgument("create", "argument 1", "str or None", args[0]);
@@ -660,10 +715,15 @@ _tkinter_create(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
         _PyArg_BadArgument("create", "argument 2", "str", args[1]);
         goto exit;
     }
-    baseName = PyUnicode_AsUTF8(args[1]);
+    Py_ssize_t baseName_length;
+    baseName = PyUnicode_AsUTF8AndSize(args[1], &baseName_length);
     if (baseName == NULL) {
         goto exit;
     }
+    if (strlen(baseName) != (size_t)baseName_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     if (nargs < 3) {
         goto skip_optional;
     }
@@ -671,10 +731,15 @@ _tkinter_create(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
         _PyArg_BadArgument("create", "argument 3", "str", args[2]);
         goto exit;
     }
-    className = PyUnicode_AsUTF8(args[2]);
+    Py_ssize_t className_length;
+    className = PyUnicode_AsUTF8AndSize(args[2], &className_length);
     if (className == NULL) {
         goto exit;
     }
+    if (strlen(className) != (size_t)className_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     if (nargs < 4) {
         goto skip_optional;
     }
@@ -710,10 +775,15 @@ _tkinter_create(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
         use = NULL;
     }
     else if (PyUnicode_Check(args[7])) {
-        use = PyUnicode_AsUTF8(args[7]);
+        Py_ssize_t use_length;
+        use = PyUnicode_AsUTF8AndSize(args[7], &use_length);
         if (use == NULL) {
             goto exit;
         }
+        if (strlen(use) != (size_t)use_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
     }
     else {
         _PyArg_BadArgument("create", "argument 8", "str or None", args[7]);
@@ -791,4 +861,4 @@ exit:
 #ifndef _TKINTER_TKAPP_DELETEFILEHANDLER_METHODDEF
     #define _TKINTER_TKAPP_DELETEFILEHANDLER_METHODDEF
 #endif /* !defined(_TKINTER_TKAPP_DELETEFILEHANDLER_METHODDEF) */
-/*[clinic end generated code: output=0c8b5f960d7738fd input=a9049054013a1b77]*/
+/*[clinic end generated code: output=d447501ec5aa9447 input=a9049054013a1b77]*/
index d91793c8be8d96bbaf7d1a6ebaa3cd65785ddb7e..9473dd70ff146066f10a90e5ee29eab2cd83ae5b 100644 (file)
@@ -4672,10 +4672,15 @@ os_getgrouplist(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
         _PyArg_BadArgument("getgrouplist", "argument 1", "str", args[0]);
         goto exit;
     }
-    user = PyUnicode_AsUTF8(args[0]);
+    Py_ssize_t user_length;
+    user = PyUnicode_AsUTF8AndSize(args[0], &user_length);
     if (user == NULL) {
         goto exit;
     }
+    if (strlen(user) != (size_t)user_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     basegid = PyLong_AsInt(args[1]);
     if (basegid == -1 && PyErr_Occurred()) {
         goto exit;
@@ -4721,10 +4726,15 @@ os_getgrouplist(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
         _PyArg_BadArgument("getgrouplist", "argument 1", "str", args[0]);
         goto exit;
     }
-    user = PyUnicode_AsUTF8(args[0]);
+    Py_ssize_t user_length;
+    user = PyUnicode_AsUTF8AndSize(args[0], &user_length);
     if (user == NULL) {
         goto exit;
     }
+    if (strlen(user) != (size_t)user_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     if (!_Py_Gid_Converter(args[1], &basegid)) {
         goto exit;
     }
@@ -12393,4 +12403,4 @@ exit:
 #ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF
     #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF
 #endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */
-/*[clinic end generated code: output=a377982a6d1e77b9 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=a05abdc48e3def44 input=a9049054013a1b77]*/
index 4fac03ebaf2a0750782fa3f8d2380b44a2b11b76..a5b93e68598204a123949754d3b2439e4024e8ac 100644 (file)
@@ -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]*/
index d624c22cf282ff2eb66dd7b35d481150bf2c4c2d..2ecd3afc00d2be493c849e879cd0f7c074c0fb3a 100644 (file)
@@ -36,13 +36,18 @@ _symtable_symtable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
         _PyArg_BadArgument("symtable", "argument 3", "str", args[2]);
         goto exit;
     }
-    startstr = PyUnicode_AsUTF8(args[2]);
+    Py_ssize_t startstr_length;
+    startstr = PyUnicode_AsUTF8AndSize(args[2], &startstr_length);
     if (startstr == NULL) {
         goto exit;
     }
+    if (strlen(startstr) != (size_t)startstr_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     return_value = _symtable_symtable_impl(module, source, filename, startstr);
 
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=9af1ab5a114a1ec7 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=931964a76a72f850 input=a9049054013a1b77]*/
index 355ae49ca74f71cf319c1d1cb9b1fe798eea649d..d95245067e260839365f794c4912d5f5e4c6981d 100644 (file)
@@ -68,10 +68,15 @@ bytearray___init__(PyObject *self, PyObject *args, PyObject *kwargs)
             _PyArg_BadArgument("bytearray", "argument 'encoding'", "str", fastargs[1]);
             goto exit;
         }
-        encoding = PyUnicode_AsUTF8(fastargs[1]);
+        Py_ssize_t encoding_length;
+        encoding = PyUnicode_AsUTF8AndSize(fastargs[1], &encoding_length);
         if (encoding == NULL) {
             goto exit;
         }
+        if (strlen(encoding) != (size_t)encoding_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
         if (!--noptargs) {
             goto skip_optional_pos;
         }
@@ -80,10 +85,15 @@ bytearray___init__(PyObject *self, PyObject *args, PyObject *kwargs)
         _PyArg_BadArgument("bytearray", "argument 'errors'", "str", fastargs[2]);
         goto exit;
     }
-    errors = PyUnicode_AsUTF8(fastargs[2]);
+    Py_ssize_t errors_length;
+    errors = PyUnicode_AsUTF8AndSize(fastargs[2], &errors_length);
     if (errors == NULL) {
         goto exit;
     }
+    if (strlen(errors) != (size_t)errors_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
 skip_optional_pos:
     return_value = bytearray___init___impl((PyByteArrayObject *)self, arg, encoding, errors);
 
@@ -950,10 +960,15 @@ bytearray_decode(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t narg
             _PyArg_BadArgument("decode", "argument 'encoding'", "str", args[0]);
             goto exit;
         }
-        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;
+        }
         if (!--noptargs) {
             goto skip_optional_pos;
         }
@@ -962,10 +977,15 @@ bytearray_decode(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t narg
         _PyArg_BadArgument("decode", "argument 'errors'", "str", args[1]);
         goto exit;
     }
-    errors = PyUnicode_AsUTF8(args[1]);
+    Py_ssize_t errors_length;
+    errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
     if (errors == NULL) {
         goto exit;
     }
+    if (strlen(errors) != (size_t)errors_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
 skip_optional_pos:
     return_value = bytearray_decode_impl(self, encoding, errors);
 
@@ -1241,4 +1261,4 @@ bytearray_sizeof(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored))
 {
     return bytearray_sizeof_impl(self);
 }
-/*[clinic end generated code: output=5a7de6295a7ce6cc input=a9049054013a1b77]*/
+/*[clinic end generated code: output=0797a5e03cda2a16 input=a9049054013a1b77]*/
index 042d0bf86e453c1962f3c24ec4f3d0b2ffcc0312..1e45be3e7aefb3e3e94edf8628d932db386bc478 100644 (file)
@@ -720,10 +720,15 @@ bytes_decode(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs, PyObj
             _PyArg_BadArgument("decode", "argument 'encoding'", "str", args[0]);
             goto exit;
         }
-        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;
+        }
         if (!--noptargs) {
             goto skip_optional_pos;
         }
@@ -732,10 +737,15 @@ bytes_decode(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs, PyObj
         _PyArg_BadArgument("decode", "argument 'errors'", "str", args[1]);
         goto exit;
     }
-    errors = PyUnicode_AsUTF8(args[1]);
+    Py_ssize_t errors_length;
+    errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
     if (errors == NULL) {
         goto exit;
     }
+    if (strlen(errors) != (size_t)errors_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
 skip_optional_pos:
     return_value = bytes_decode_impl(self, encoding, errors);
 
@@ -987,10 +997,15 @@ bytes_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
             _PyArg_BadArgument("bytes", "argument 'encoding'", "str", fastargs[1]);
             goto exit;
         }
-        encoding = PyUnicode_AsUTF8(fastargs[1]);
+        Py_ssize_t encoding_length;
+        encoding = PyUnicode_AsUTF8AndSize(fastargs[1], &encoding_length);
         if (encoding == NULL) {
             goto exit;
         }
+        if (strlen(encoding) != (size_t)encoding_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
         if (!--noptargs) {
             goto skip_optional_pos;
         }
@@ -999,14 +1014,19 @@ bytes_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
         _PyArg_BadArgument("bytes", "argument 'errors'", "str", fastargs[2]);
         goto exit;
     }
-    errors = PyUnicode_AsUTF8(fastargs[2]);
+    Py_ssize_t errors_length;
+    errors = PyUnicode_AsUTF8AndSize(fastargs[2], &errors_length);
     if (errors == NULL) {
         goto exit;
     }
+    if (strlen(errors) != (size_t)errors_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
 skip_optional_pos:
     return_value = bytes_new_impl(type, x, encoding, errors);
 
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=97aab3f6ae398664 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=8a49dbbd78914a6f input=a9049054013a1b77]*/
index 8c331197f05b5c2a8d4b89c417dc9e3475f4c7b6..10f6149cc88c22fe34f69ea1366ab0e9cec9f109 100644 (file)
@@ -275,10 +275,15 @@ float___getformat__(PyTypeObject *type, PyObject *arg)
         _PyArg_BadArgument("__getformat__", "argument", "str", arg);
         goto exit;
     }
-    typestr = PyUnicode_AsUTF8(arg);
+    Py_ssize_t typestr_length;
+    typestr = PyUnicode_AsUTF8AndSize(arg, &typestr_length);
     if (typestr == NULL) {
         goto exit;
     }
+    if (strlen(typestr) != (size_t)typestr_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     return_value = float___getformat___impl(type, typestr);
 
 exit:
@@ -313,4 +318,4 @@ float___format__(PyObject *self, PyObject *arg)
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=01f6fbd082eefead input=a9049054013a1b77]*/
+/*[clinic end generated code: output=c79743c8551c30d9 input=a9049054013a1b77]*/
index ebc1e0617bd303735bf58eb7fdbba448a4908fcb..f199434dacb9e813858e4661a82aceb40c2ddfb1 100644 (file)
@@ -305,10 +305,15 @@ memoryview_tobytes(PyMemoryViewObject *self, PyObject *const *args, Py_ssize_t n
         order = NULL;
     }
     else if (PyUnicode_Check(args[0])) {
-        order = PyUnicode_AsUTF8(args[0]);
+        Py_ssize_t order_length;
+        order = PyUnicode_AsUTF8AndSize(args[0], &order_length);
         if (order == NULL) {
             goto exit;
         }
+        if (strlen(order) != (size_t)order_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
     }
     else {
         _PyArg_BadArgument("tobytes", "argument 'order'", "str or None", args[0]);
@@ -408,4 +413,4 @@ skip_optional_pos:
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=abd8c0ce804d8992 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=7e76a09106921ba2 input=a9049054013a1b77]*/
index 83e3bf229898489564faae06e9dc1b2f2618670c..7711434f17c2bc5e1dad2499ee7e767a72a915f3 100644 (file)
@@ -203,10 +203,15 @@ unicode_encode(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject
             _PyArg_BadArgument("encode", "argument 'encoding'", "str", args[0]);
             goto exit;
         }
-        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;
+        }
         if (!--noptargs) {
             goto skip_optional_pos;
         }
@@ -215,10 +220,15 @@ unicode_encode(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject
         _PyArg_BadArgument("encode", "argument 'errors'", "str", args[1]);
         goto exit;
     }
-    errors = PyUnicode_AsUTF8(args[1]);
+    Py_ssize_t errors_length;
+    errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
     if (errors == NULL) {
         goto exit;
     }
+    if (strlen(errors) != (size_t)errors_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
 skip_optional_pos:
     return_value = unicode_encode_impl(self, encoding, errors);
 
@@ -1463,10 +1473,15 @@ unicode_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
             _PyArg_BadArgument("str", "argument 'encoding'", "str", fastargs[1]);
             goto exit;
         }
-        encoding = PyUnicode_AsUTF8(fastargs[1]);
+        Py_ssize_t encoding_length;
+        encoding = PyUnicode_AsUTF8AndSize(fastargs[1], &encoding_length);
         if (encoding == NULL) {
             goto exit;
         }
+        if (strlen(encoding) != (size_t)encoding_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
         if (!--noptargs) {
             goto skip_optional_pos;
         }
@@ -1475,14 +1490,19 @@ unicode_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
         _PyArg_BadArgument("str", "argument 'errors'", "str", fastargs[2]);
         goto exit;
     }
-    errors = PyUnicode_AsUTF8(fastargs[2]);
+    Py_ssize_t errors_length;
+    errors = PyUnicode_AsUTF8AndSize(fastargs[2], &errors_length);
     if (errors == NULL) {
         goto exit;
     }
+    if (strlen(errors) != (size_t)errors_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
 skip_optional_pos:
     return_value = unicode_new_impl(type, x, encoding, errors);
 
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=20313d6339272ddc input=a9049054013a1b77]*/
+/*[clinic end generated code: output=873d8b3d09af3095 input=a9049054013a1b77]*/
index f44e30cf0446a5e128729b96232bfe8d5c20f51e..557464c6740c1805d2b0a95f2a9ea02f67b18a27 100644 (file)
@@ -3501,14 +3501,13 @@ type_new_set_doc(PyTypeObject *type)
         return 0;
     }
 
-    Py_ssize_t doc_size;
-    const char *doc_str = PyUnicode_AsUTF8AndSize(doc, &doc_size);
+    const char *doc_str = PyUnicode_AsUTF8(doc);
     if (doc_str == NULL) {
         return -1;
     }
 
     // Silently truncate the docstring if it contains a null byte
-    Py_ssize_t size = doc_size + 1;
+    Py_ssize_t size = strlen(doc_str) + 1;
     char *tp_doc = (char *)PyObject_Malloc(size);
     if (tp_doc == NULL) {
         PyErr_NoMemory();
index 87636efcfca0503dea153f0054782bfbb805f168..53e1e56babf952bf5ed9c13338a83c35f9a00bfc 100644 (file)
@@ -3844,13 +3844,7 @@ PyUnicode_AsUTF8AndSize(PyObject *unicode, Py_ssize_t *psize)
 const char *
 PyUnicode_AsUTF8(PyObject *unicode)
 {
-    Py_ssize_t size;
-    const char *utf8 = PyUnicode_AsUTF8AndSize(unicode, &size);
-    if (utf8 != NULL && strlen(utf8) != (size_t)size) {
-        PyErr_SetString(PyExc_ValueError, "embedded null character");
-        return NULL;
-    }
-    return utf8;
+    return PyUnicode_AsUTF8AndSize(unicode, NULL);
 }
 
 /*
index fa6bf1f0282b0a1cf0547d2f19fab7b53fefc95f..07aa84c91f9fc7fa0ead17831d135672140f9fe4 100755 (executable)
@@ -662,7 +662,6 @@ EXPORT_FUNC(PyUnicode_AsUCS4Copy)
 EXPORT_FUNC(PyUnicode_AsUnicodeEscapeString)
 EXPORT_FUNC(PyUnicode_AsUTF16String)
 EXPORT_FUNC(PyUnicode_AsUTF32String)
-EXPORT_FUNC(PyUnicode_AsUTF8)
 EXPORT_FUNC(PyUnicode_AsUTF8AndSize)
 EXPORT_FUNC(PyUnicode_AsUTF8String)
 EXPORT_FUNC(PyUnicode_AsWideChar)
index 7417020d94c2f2699d8fa9c4963f8b9c31fe8264..730fa8ef2a21546fa85a3bbe638d89352d7c5d10 100644 (file)
@@ -65,14 +65,19 @@ tokenizeriter_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
         _PyArg_BadArgument("tokenizeriter", "argument 'encoding'", "str", fastargs[2]);
         goto exit;
     }
-    encoding = PyUnicode_AsUTF8(fastargs[2]);
+    Py_ssize_t encoding_length;
+    encoding = PyUnicode_AsUTF8AndSize(fastargs[2], &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_kwonly:
     return_value = tokenizeriter_new_impl(type, readline, extra_tokens, encoding);
 
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=92cb8176149f0924 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=dcd6ec48f06a092e input=a9049054013a1b77]*/
index 4fb06bd0dba5fea58a7f4ce5747e27cedb9861c5..8d40e659b54a57ea2a33a6db09062b1d734a6d1e 100644 (file)
@@ -329,10 +329,15 @@ builtin_compile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObj
         _PyArg_BadArgument("compile", "argument 'mode'", "str", args[2]);
         goto exit;
     }
-    mode = PyUnicode_AsUTF8(args[2]);
+    Py_ssize_t mode_length;
+    mode = PyUnicode_AsUTF8AndSize(args[2], &mode_length);
     if (mode == NULL) {
         goto exit;
     }
+    if (strlen(mode) != (size_t)mode_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     if (!noptargs) {
         goto skip_optional_pos;
     }
@@ -1207,4 +1212,4 @@ builtin_issubclass(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=95d3813b1798f018 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=31bded5d08647a57 input=a9049054013a1b77]*/
index 571a34bd4a64af15fa632365bd8a0e097608e16f..98717ecc875b8bcede7145d385d7c7c1833c8a44 100644 (file)
@@ -1259,10 +1259,15 @@ sys_activate_stack_trampoline(PyObject *module, PyObject *arg)
         _PyArg_BadArgument("activate_stack_trampoline", "argument", "str", arg);
         goto exit;
     }
-    backend = PyUnicode_AsUTF8(arg);
+    Py_ssize_t backend_length;
+    backend = PyUnicode_AsUTF8AndSize(arg, &backend_length);
     if (backend == NULL) {
         goto exit;
     }
+    if (strlen(backend) != (size_t)backend_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     return_value = sys_activate_stack_trampoline_impl(module, backend);
 
 exit:
@@ -1447,4 +1452,4 @@ exit:
 #ifndef SYS_GETANDROIDAPILEVEL_METHODDEF
     #define SYS_GETANDROIDAPILEVEL_METHODDEF
 #endif /* !defined(SYS_GETANDROIDAPILEVEL_METHODDEF) */
-/*[clinic end generated code: output=cdfb714878deeaf1 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=f36d45c829250775 input=a9049054013a1b77]*/
index 4d91818ad21a444f9deab55139b9b69ccfd5af6f..5a12ca8def74faa99bde5838e4c755b5ef37f47f 100644 (file)
@@ -932,15 +932,19 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
         } else {
             /* "s" or "z" */
             const char **p = va_arg(*p_va, const char **);
+            Py_ssize_t len;
             sarg = NULL;
 
             if (c == 'z' && arg == Py_None)
                 *p = NULL;
             else if (PyUnicode_Check(arg)) {
-                sarg = PyUnicode_AsUTF8(arg);
-                if (sarg == NULL) {
+                sarg = PyUnicode_AsUTF8AndSize(arg, &len);
+                if (sarg == NULL)
                     return converterr(CONV_UNICODE,
                                       arg, msgbuf, bufsize);
+                if (strlen(sarg) != (size_t)len) {
+                    PyErr_SetString(PyExc_ValueError, "embedded null character");
+                    RETURN_ERR_OCCURRED;
                 }
                 *p = sarg;
             }
index 4f238a3dc0d4af3bf3be1695d162e238fbd43ba3..5f94b90ae09bd0eff208dfcff0ad8df35de216bf 100755 (executable)
@@ -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)
 
 #