summaryrefslogtreecommitdiffstats
path: root/Modules/_io
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-04-20 06:53:58 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-04-20 06:53:58 (GMT)
commit2b0d2007a1a51a15a67dc7297cf5e21c8767b563 (patch)
tree4e8eebbb9db682202b19d2a8af246ed3cc730fb8 /Modules/_io
parent2ef7c478444f453a04ae63ecc3d3de07915ad2b0 (diff)
downloadcpython-2b0d2007a1a51a15a67dc7297cf5e21c8767b563.zip
cpython-2b0d2007a1a51a15a67dc7297cf5e21c8767b563.tar.gz
cpython-2b0d2007a1a51a15a67dc7297cf5e21c8767b563.tar.bz2
Issue #23908: os functions now reject paths with embedded null character
on Windows instead of silently truncate them.
Diffstat (limited to 'Modules/_io')
-rw-r--r--Modules/_io/fileio.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c
index 95bcb77..74508a7 100644
--- a/Modules/_io/fileio.c
+++ b/Modules/_io/fileio.c
@@ -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)