]> granicus.if.org Git - python/commitdiff
Issue #8734: Avoid crash in msvcrt.get_osfhandle() when an invalid file
authorAntoine Pitrou <solipsis@pitrou.net>
Sat, 4 Sep 2010 20:53:29 +0000 (20:53 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Sat, 4 Sep 2010 20:53:29 +0000 (20:53 +0000)
descriptor is provided.  Patch by Pascal Chambon.

Lib/test/test_fileio.py
Misc/NEWS
PC/msvcrtmodule.c

index 63bc1d9781e18481a27457851439d42de821c01b..4b48d41f6caed13d7df08dc5c1e74c4bac39cfa3 100644 (file)
@@ -309,6 +309,9 @@ class OtherFileTests(unittest.TestCase):
     def testInvalidFd(self):
         self.assertRaises(ValueError, _FileIO, -10)
         self.assertRaises(OSError, _FileIO, make_bad_fd())
+        if sys.platform == 'win32':
+            import msvcrt
+            self.assertRaises(IOError, msvcrt.get_osfhandle, make_bad_fd())
 
     def testBadModeArgument(self):
         # verify that we get a sensible error message for bad mode argument
index f413da2e5a61365132d4f420571ee9944938e25f..5d3656066e240b4c8a3aa931382dc479a1367cba 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -100,6 +100,9 @@ Core and Builtins
 Extensions
 ----------
 
+- Issue #8734: Avoid crash in msvcrt.get_osfhandle() when an invalid file
+  descriptor is provided.  Patch by Pascal Chambon.
+
 - Issue #7736: Release the GIL around calls to opendir() and closedir()
   in the posix module.  Patch by Marcin Bachry.
 
index e173fea8b033c044b206d9fdd163b51e30b75c50..166df036f2dad83247cb685f73737a4762710958 100755 (executable)
@@ -143,6 +143,9 @@ msvcrt_get_osfhandle(PyObject *self, PyObject *args)
     if (!PyArg_ParseTuple(args,"i:get_osfhandle", &fd))
         return NULL;
 
+    if (!_PyVerify_fd(fd))
+        return PyErr_SetFromErrno(PyExc_IOError);
+
     handle = _get_osfhandle(fd);
     if (handle == -1)
         return PyErr_SetFromErrno(PyExc_IOError);