diff options
Diffstat (limited to 'Python')
| -rw-r--r-- | Python/clinic/Python-tokenize.c.h | 9 | ||||
| -rw-r--r-- | Python/clinic/bltinmodule.c.h | 9 | ||||
| -rw-r--r-- | Python/clinic/sysmodule.c.h | 9 | ||||
| -rw-r--r-- | Python/getargs.c | 8 |
4 files changed, 27 insertions, 8 deletions
diff --git a/Python/clinic/Python-tokenize.c.h b/Python/clinic/Python-tokenize.c.h index 7417020..730fa8e 100644 --- a/Python/clinic/Python-tokenize.c.h +++ b/Python/clinic/Python-tokenize.c.h @@ -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]*/ diff --git a/Python/clinic/bltinmodule.c.h b/Python/clinic/bltinmodule.c.h index 4fb06bd..8d40e65 100644 --- a/Python/clinic/bltinmodule.c.h +++ b/Python/clinic/bltinmodule.c.h @@ -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]*/ diff --git a/Python/clinic/sysmodule.c.h b/Python/clinic/sysmodule.c.h index 571a34b..98717ec 100644 --- a/Python/clinic/sysmodule.c.h +++ b/Python/clinic/sysmodule.c.h @@ -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]*/ diff --git a/Python/getargs.c b/Python/getargs.c index 4d91818..5a12ca8 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -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; } |
