diff options
Diffstat (limited to 'Modules/_io/clinic/_iomodule.c.h')
-rw-r--r-- | Modules/_io/clinic/_iomodule.c.h | 30 |
1 files changed, 25 insertions, 5 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]*/ |