mirror of
https://github.com/python/cpython.git
synced 2025-08-01 15:43:13 +00:00
#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.
This commit is contained in:
parent
22d3c92480
commit
17617a07d1
3 changed files with 24 additions and 4 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue