gh-74616: Raise ValueError in case of null character in input prompt (GH-1738)

If the input prompt to the builtin input function on terminal has any null
character, then raise ValueError instead of silently truncating it.

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
Kushal Das 2023-12-07 11:22:52 +01:00 committed by GitHub
parent 8660fb7fd7
commit 4ba15de191
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 9 deletions

View file

@ -2262,6 +2262,11 @@ builtin_input_impl(PyObject *module, PyObject *prompt)
goto _readline_errors;
assert(PyBytes_Check(po));
promptstr = PyBytes_AS_STRING(po);
if ((Py_ssize_t)strlen(promptstr) != PyBytes_GET_SIZE(po)) {
PyErr_SetString(PyExc_ValueError,
"input: prompt string cannot contain null characters");
goto _readline_errors;
}
}
else {
po = NULL;