From: Antoine Pitrou Date: Sun, 29 Jan 2012 17:43:36 +0000 (+0100) Subject: Issue #13848: open() and the FileIO constructor now check for NUL characters in the... X-Git-Tag: v3.3.0a1~282 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7ab4af0427a100e1054dea6137381c5dbf843530;p=python Issue #13848: open() and the FileIO constructor now check for NUL characters in the file name. Patch by Hynek Schlawack. --- 7ab4af0427a100e1054dea6137381c5dbf843530 diff --cc Modules/_io/fileio.c index a21aa7a12d,d5b03eec26..34ff1e02ee --- a/Modules/_io/fileio.c +++ b/Modules/_io/fileio.c @@@ -258,10 -254,15 +258,16 @@@ fileio_init(PyObject *oself, PyObject * #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_AS_UNICODE(nameobj); - } - if (widename == NULL) + widename = PyUnicode_AsUnicode(nameobj); + if (widename == NULL) + return -1; + } else #endif if (fd < 0) {