]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Merged revisions 84506 via svnmerge from
authorAntoine Pitrou <solipsis@pitrou.net>
Sat, 4 Sep 2010 21:24:42 +0000 (21:24 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Sat, 4 Sep 2010 21:24:42 +0000 (21:24 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r84506 | antoine.pitrou | 2010-09-04 22:53:29 +0200 (sam., 04 sept. 2010) | 5 lines

  Issue #8734: Avoid crash in msvcrt.get_osfhandle() when an invalid file
  descriptor is provided.  Patch by Pascal Chambon.
........

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

index 930b6543b614d76a81132246ed99991c2f2664d6..2760b733c514c9b796f5515b62420b15a54439ed 100644 (file)
@@ -312,6 +312,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 8ac6168da5c02f92c6a08e2d61b969a63c11bbbe..b205fa5aff8667d7a15c566abd93615cd12f757a 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -228,6 +228,9 @@ Library
 Extension Modules
 -----------------
 
+- 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 68b7d2432e6469800b1ee9b25be8e9d7faa9b751..057900d98057d5ff64ecb066f795fd0a9c16a370 100755 (executable)
@@ -141,6 +141,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);