summaryrefslogtreecommitdiffstats
path: root/Modules/posixmodule.c
diff options
context:
space:
mode:
authorRichard Oudkerk <shibturn@gmail.com>2012-07-06 11:05:32 (GMT)
committerRichard Oudkerk <shibturn@gmail.com>2012-07-06 11:05:32 (GMT)
commit2240ac1eae2dd8674748239af9c61e5ab4faeb2c (patch)
tree9e851d9c9d9df1a377e1fd95ed27a9f29f923313 /Modules/posixmodule.c
parent74de1536810946f82c1e6526fff55646fa119b3d (diff)
downloadcpython-2240ac1eae2dd8674748239af9c61e5ab4faeb2c.zip
cpython-2240ac1eae2dd8674748239af9c61e5ab4faeb2c.tar.gz
cpython-2240ac1eae2dd8674748239af9c61e5ab4faeb2c.tar.bz2
Issue #15261: Stop os.stat(fd) crashing on Windows when fd not open.
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r--Modules/posixmodule.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 1bd5e97..b99a5fe 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -1829,7 +1829,10 @@ win32_fstat(int file_number, struct win32_stat *result)
HANDLE h;
int type;
- h = (HANDLE)_get_osfhandle(file_number);
+ if (!_PyVerify_fd(file_number))
+ h = INVALID_HANDLE_VALUE;
+ else
+ h = (HANDLE)_get_osfhandle(file_number);
/* Protocol violation: we explicitly clear errno, instead of
setting it to a POSIX error. Callers should use GetLastError. */
@@ -8244,8 +8247,6 @@ posix_fstat(PyObject *self, PyObject *args)
/* on OpenVMS we must ensure that all bytes are written to the file */
fsync(fd);
#endif
- if (!_PyVerify_fd(fd))
- return posix_error();
Py_BEGIN_ALLOW_THREADS
res = FSTAT(fd, &st);
Py_END_ALLOW_THREADS