diff options
author | Victor Stinner <vstinner@python.org> | 2023-11-07 22:36:13 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-07 22:36:13 (GMT) |
commit | 11e83488c5a4a6e75a4f363a2e1a45574fd53573 (patch) | |
tree | 4d3ad20c063f098a2b142aace0baade00e465ac9 /Modules/_multiprocessing | |
parent | ea970fb116a114f2c47cc8f21df00166d43ab78b (diff) | |
download | cpython-11e83488c5a4a6e75a4f363a2e1a45574fd53573.zip cpython-11e83488c5a4a6e75a4f363a2e1a45574fd53573.tar.gz cpython-11e83488c5a4a6e75a4f363a2e1a45574fd53573.tar.bz2 |
gh-111089: Revert PyUnicode_AsUTF8() changes (#111833)
* Revert "gh-111089: Use PyUnicode_AsUTF8() in Argument Clinic (#111585)"
This reverts commit d9b606b3d04fc56fb0bcc479d7d6c14562edb5e2.
* Revert "gh-111089: Use PyUnicode_AsUTF8() in getargs.c (#111620)"
This reverts commit cde1071b2a72e8261ca66053ef61431b7f3a81fd.
* Revert "gh-111089: PyUnicode_AsUTF8() now raises on embedded NUL (#111091)"
This reverts commit d731579bfb9a497cfb0076cb6b221058a20088fe.
* Revert "gh-111089: Add PyUnicode_AsUTF8() to the limited C API (#111121)"
This reverts commit d8f32be5b6a736dc2fc9dca3f1bf176c82fc9b44.
* Revert "gh-111089: Use PyUnicode_AsUTF8() in sqlite3 (#111122)"
This reverts commit 37e4e20eaa8f27ada926d49e5971fecf0477ad26.
Diffstat (limited to 'Modules/_multiprocessing')
-rw-r--r-- | Modules/_multiprocessing/clinic/multiprocessing.c.h | 9 | ||||
-rw-r--r-- | Modules/_multiprocessing/clinic/semaphore.c.h | 9 | ||||
-rw-r--r-- | Modules/_multiprocessing/posixshmem.c | 4 |
3 files changed, 16 insertions, 6 deletions
diff --git a/Modules/_multiprocessing/clinic/multiprocessing.c.h b/Modules/_multiprocessing/clinic/multiprocessing.c.h index 9133d5d..6d4f5c2 100644 --- a/Modules/_multiprocessing/clinic/multiprocessing.c.h +++ b/Modules/_multiprocessing/clinic/multiprocessing.c.h @@ -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]*/ diff --git a/Modules/_multiprocessing/clinic/semaphore.c.h b/Modules/_multiprocessing/clinic/semaphore.c.h index ae340c2..7c85511 100644 --- a/Modules/_multiprocessing/clinic/semaphore.c.h +++ b/Modules/_multiprocessing/clinic/semaphore.c.h @@ -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]*/ diff --git a/Modules/_multiprocessing/posixshmem.c b/Modules/_multiprocessing/posixshmem.c index b1f776c..cd08a9f 100644 --- a/Modules/_multiprocessing/posixshmem.c +++ b/Modules/_multiprocessing/posixshmem.c @@ -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; } |