summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2012-01-29 17:43:36 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2012-01-29 17:43:36 (GMT)
commit7ab4af0427a100e1054dea6137381c5dbf843530 (patch)
tree5675c8aba99f23694645917896e81ce877263d20 /Modules
parentcdc878e56298c9da9720f1298a8b780a189ce029 (diff)
parent1334884ff2f5a3968e6a26157f869b4ca5de189b (diff)
downloadcpython-7ab4af0427a100e1054dea6137381c5dbf843530.zip
cpython-7ab4af0427a100e1054dea6137381c5dbf843530.tar.gz
cpython-7ab4af0427a100e1054dea6137381c5dbf843530.tar.bz2
Issue #13848: open() and the FileIO constructor now check for NUL characters in the file name.
Patch by Hynek Schlawack.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_io/fileio.c30
1 files changed, 9 insertions, 21 deletions
diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c
index a21aa7a..34ff1e0 100644
--- a/Modules/_io/fileio.c
+++ b/Modules/_io/fileio.c
@@ -258,6 +258,12 @@ 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);
if (widename == NULL)
return -1;
@@ -265,28 +271,10 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
#endif
if (fd < 0)
{
- if (PyBytes_Check(nameobj) || PyByteArray_Check(nameobj)) {
- Py_ssize_t namelen;
- if (PyObject_AsCharBuffer(nameobj, &name, &namelen) < 0)
- return -1;
- }
- else {
- PyObject *u = PyUnicode_FromObject(nameobj);
-
- if (u == NULL)
- return -1;
-
- stringobj = PyUnicode_EncodeFSDefault(u);
- Py_DECREF(u);
- if (stringobj == NULL)
- return -1;
- if (!PyBytes_Check(stringobj)) {
- PyErr_SetString(PyExc_TypeError,
- "encoder failed to return bytes");
- goto error;
- }
- name = PyBytes_AS_STRING(stringobj);
+ if (!PyUnicode_FSConverter(nameobj, &stringobj)) {
+ return -1;
}
+ name = PyBytes_AS_STRING(stringobj);
}
s = mode;