Enforce valid filemode. Fixes SF Bug #623464.

This commit is contained in:
Thomas Heller 2002-11-07 16:00:59 +00:00
parent e3271209e7
commit 1f043e28f4
1 changed files with 6 additions and 0 deletions

View File

@ -5048,6 +5048,12 @@ posix_fdopen(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "i|si", &fd, &mode, &bufsize))
return NULL;
if (mode[0] != 'r' && mode[0] != 'w' && mode[0] != 'a') {
PyErr_Format(PyExc_ValueError,
"invalid file mode '%s'", mode);
return NULL;
}
Py_BEGIN_ALLOW_THREADS
fp = fdopen(fd, mode);
Py_END_ALLOW_THREADS