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/_io | |
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/_io')
-rw-r--r-- | Modules/_io/clinic/_iomodule.c.h | 30 | ||||
-rw-r--r-- | Modules/_io/clinic/fileio.c.h | 9 | ||||
-rw-r--r-- | Modules/_io/clinic/textio.c.h | 23 | ||||
-rw-r--r-- | Modules/_io/clinic/winconsoleio.c.h | 9 |
4 files changed, 58 insertions, 13 deletions
diff --git a/Modules/_io/clinic/_iomodule.c.h b/Modules/_io/clinic/_iomodule.c.h index 68a8a20..112408a 100644 --- a/Modules/_io/clinic/_iomodule.c.h +++ b/Modules/_io/clinic/_iomodule.c.h @@ -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]*/ diff --git a/Modules/_io/clinic/fileio.c.h b/Modules/_io/clinic/fileio.c.h index 6f5d660..cf3ba28 100644 --- a/Modules/_io/clinic/fileio.c.h +++ b/Modules/_io/clinic/fileio.c.h @@ -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]*/ diff --git a/Modules/_io/clinic/textio.c.h b/Modules/_io/clinic/textio.c.h index 25c301e..b24a166 100644 --- a/Modules/_io/clinic/textio.c.h +++ b/Modules/_io/clinic/textio.c.h @@ -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]*/ diff --git a/Modules/_io/clinic/winconsoleio.c.h b/Modules/_io/clinic/winconsoleio.c.h index 8609fc9..6cab295 100644 --- a/Modules/_io/clinic/winconsoleio.c.h +++ b/Modules/_io/clinic/winconsoleio.c.h @@ -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]*/ |