Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0049249

Browse files
committed
Issue #8734: Avoid crash in msvcrt.get_osfhandle() when an invalid file
descriptor is provided. Patch by Pascal Chambon.
1 parent 7d6e076 commit 0049249

3 files changed

Lines changed: 9 additions & 0 deletions

File tree

Lib/test/test_fileio.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,9 @@ def testBytesOpen(self):
309309
def testInvalidFd(self):
310310
self.assertRaises(ValueError, _FileIO, -10)
311311
self.assertRaises(OSError, _FileIO, make_bad_fd())
312+
if sys.platform == 'win32':
313+
import msvcrt
314+
self.assertRaises(IOError, msvcrt.get_osfhandle, make_bad_fd())
312315

313316
def testBadModeArgument(self):
314317
# verify that we get a sensible error message for bad mode argument

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ Core and Builtins
100100
Extensions
101101
----------
102102

103+
- Issue #8734: Avoid crash in msvcrt.get_osfhandle() when an invalid file
104+
descriptor is provided. Patch by Pascal Chambon.
105+
103106
- Issue #7736: Release the GIL around calls to opendir() and closedir()
104107
in the posix module. Patch by Marcin Bachry.
105108

PC/msvcrtmodule.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ msvcrt_get_osfhandle(PyObject *self, PyObject *args)
143143
if (!PyArg_ParseTuple(args,"i:get_osfhandle", &fd))
144144
return NULL;
145145

146+
if (!_PyVerify_fd(fd))
147+
return PyErr_SetFromErrno(PyExc_IOError);
148+
146149
handle = _get_osfhandle(fd);
147150
if (handle == -1)
148151
return PyErr_SetFromErrno(PyExc_IOError);

0 commit comments

Comments
 (0)