summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-04-20 07:12:28 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-04-20 07:12:28 (GMT)
commit7e9d1d1a1b8ec4db9b9b6789b448c4202ab84b48 (patch)
tree0cecdabe5db216090cd9fb763bf3cd6c3b2165e3 /Modules
parente3037e114509913874a28746f5e05780919e909a (diff)
parent2b0d2007a1a51a15a67dc7297cf5e21c8767b563 (diff)
downloadcpython-7e9d1d1a1b8ec4db9b9b6789b448c4202ab84b48.zip
cpython-7e9d1d1a1b8ec4db9b9b6789b448c4202ab84b48.tar.gz
cpython-7e9d1d1a1b8ec4db9b9b6789b448c4202ab84b48.tar.bz2
Issue #23908: os functions now reject paths with embedded null character
on Windows instead of silently truncate them. Removed no longer used _PyUnicode_HasNULChars().
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_io/fileio.c13
-rw-r--r--Modules/posixmodule.c5
2 files changed, 11 insertions, 7 deletions
diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c
index 145d93a..0894ca4 100644
--- a/Modules/_io/fileio.c
+++ b/Modules/_io/fileio.c
@@ -281,15 +281,14 @@ _io_FileIO___init___impl(fileio *self, PyObject *nameobj, const char *mode,
#ifdef MS_WINDOWS
if (PyUnicode_Check(nameobj)) {
- int rv = _PyUnicode_HasNULChars(nameobj);
- if (rv) {
- if (rv != -1)
- PyErr_SetString(PyExc_ValueError, "embedded null 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_ValueError, "embedded null character");
+ return -1;
+ }
} else
#endif
if (fd < 0)
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 89fb08b..90d820f 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -866,6 +866,11 @@ path_converter(PyObject *o, void *p) {
Py_DECREF(unicode);
return 0;
}
+ if (wcslen(wide) != length) {
+ FORMAT_EXCEPTION(PyExc_ValueError, "embedded null character");
+ Py_DECREF(unicode);
+ return 0;
+ }
path->wide = wide;
path->narrow = NULL;