summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>2008-09-25 20:52:56 (GMT)
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>2008-09-25 20:52:56 (GMT)
commit17617a07d1f2d2ffb6b0f77be8926f54cd0f4ae8 (patch)
tree90b9bdabd59ba83dabbdea1f49ac745a22a7fe43 /Objects
parent22d3c92480b419c4ad1adf42ffb723ba2d471f26 (diff)
downloadcpython-17617a07d1f2d2ffb6b0f77be8926f54cd0f4ae8.zip
cpython-17617a07d1f2d2ffb6b0f77be8926f54cd0f4ae8.tar.gz
cpython-17617a07d1f2d2ffb6b0f77be8926f54cd0f4ae8.tar.bz2
#3965: on Windows, open() crashes if the filename or the mode is invalid,
and if the filename is a unicode string. Reviewed by Martin von Loewis.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/fileobject.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/Objects/fileobject.c b/Objects/fileobject.c
index a8e95a2..b2051d7 100644
--- a/Objects/fileobject.c
+++ b/Objects/fileobject.c
@@ -305,10 +305,17 @@ open_the_file(PyFileObject *f, char *name, char *mode)
#endif
/* EINVAL is returned when an invalid filename or
* an invalid mode is supplied. */
- if (errno == EINVAL)
- PyErr_Format(PyExc_IOError,
- "invalid filename: %s or mode: %s",
- name, mode);
+ if (errno == EINVAL) {
+ PyObject *v;
+ char message[100];
+ PyOS_snprintf(message, 100,
+ "invalid mode ('%.50s') or filename", mode);
+ v = Py_BuildValue("(isO)", errno, message, f->f_name);
+ if (v != NULL) {
+ PyErr_SetObject(PyExc_IOError, v);
+ Py_DECREF(v);
+ }
+ }
else
PyErr_SetFromErrnoWithFilenameObject(PyExc_IOError, f->f_name);
f = NULL;