]> granicus.if.org Git - python/commitdiff
Merged revisions 84506 via svnmerge from
authorAntoine Pitrou <solipsis@pitrou.net>
Sat, 4 Sep 2010 21:02:41 +0000 (21:02 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Sat, 4 Sep 2010 21:02:41 +0000 (21:02 +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 f89c542d1924dbb93f925f6a06fdcd36b35be7dd..2f299dc32e2238452a9c5d4fbe8b1d92beae9ead 100644 (file)
@@ -313,6 +313,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 871396baea5d48dc1156230a13db55265aeeaa76..2ff4ff44ebd3a311527ba35a6d70857b789741e1 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -477,6 +477,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 9a86d5e43848ec20e1f14c7f7f5585fab9850449..37631a7792358f884e5422776e91204788691312 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);