mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #23908: os functions now reject paths with embedded null character
on Windows instead of silently truncate them.
This commit is contained in:
parent
2ef7c47844
commit
2b0d2007a1
4 changed files with 50 additions and 7 deletions
|
@ -275,15 +275,14 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
|
|||
|
||||
#ifdef MS_WINDOWS
|
||||
if (PyUnicode_Check(nameobj)) {
|
||||
int rv = _PyUnicode_HasNULChars(nameobj);
|
||||
if (rv) {
|
||||
if (rv != -1)
|
||||
PyErr_SetString(PyExc_TypeError, "embedded NUL character");
|
||||
return -1;
|
||||
}
|
||||
widename = PyUnicode_AsUnicode(nameobj);
|
||||
Py_ssize_t length;
|
||||
widename = PyUnicode_AsUnicodeAndSize(nameobj, &length);
|
||||
if (widename == NULL)
|
||||
return -1;
|
||||
if (wcslen(widename) != length) {
|
||||
PyErr_SetString(PyExc_TypeError, "embedded NUL character");
|
||||
return -1;
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
if (fd < 0)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue