diff options
author | Benjamin Peterson <benjamin@python.org> | 2009-01-19 15:11:51 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2009-01-19 15:11:51 (GMT) |
commit | 806d4029ed3d6adca2effe5b3b2fd461b300aebb (patch) | |
tree | 40c102cce986df99ace78d8e1d65d43df18151b4 /Modules | |
parent | d994864d54ffd2f607af3a9eecfbadd75502efd3 (diff) | |
download | cpython-806d4029ed3d6adca2effe5b3b2fd461b300aebb.zip cpython-806d4029ed3d6adca2effe5b3b2fd461b300aebb.tar.gz cpython-806d4029ed3d6adca2effe5b3b2fd461b300aebb.tar.bz2 |
Merged revisions 68755 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r68755 | benjamin.peterson | 2009-01-18 18:08:08 -0600 (Sun, 18 Jan 2009) | 1 line
raise an OSError for invalid fds #4991
........
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_fileio.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Modules/_fileio.c b/Modules/_fileio.c index 8579e4e..03632f7 100644 --- a/Modules/_fileio.c +++ b/Modules/_fileio.c @@ -138,6 +138,24 @@ dircheck(PyFileIOObject* self, char *name) return 0; } +static int +check_fd(int fd) +{ +#if defined(HAVE_FSTAT) + struct stat buf; + if (fstat(fd, &buf) < 0 && errno == EBADF) { + PyObject *exc; + char *msg = strerror(EBADF); + exc = PyObject_CallFunction(PyExc_OSError, "(is)", + EBADF, msg); + PyErr_SetObject(PyExc_OSError, exc); + Py_XDECREF(exc); + return -1; + } +#endif + return 0; +} + static int fileio_init(PyObject *oself, PyObject *args, PyObject *kwds) @@ -170,6 +188,8 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds) "Negative filedescriptor"); return -1; } + if (check_fd(fd)) + return -1; } else { PyErr_Clear(); |