diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 0cf00223c22..9dc1d05d08e 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -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