From 1f043e28f4d8cb4a32da3b07f3719647ba3078b2 Mon Sep 17 00:00:00 2001 From: Thomas Heller Date: Thu, 7 Nov 2002 16:00:59 +0000 Subject: Enforce valid filemode. Fixes SF Bug #623464. --- Modules/posixmodule.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 0cf0022..9dc1d05 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 -- cgit v0.12