]> granicus.if.org Git - python/commitdiff
check windows fd validity (closes #16992)
authorBenjamin Peterson <benjamin@python.org>
Fri, 18 Jan 2013 05:10:24 +0000 (00:10 -0500)
committerBenjamin Peterson <benjamin@python.org>
Fri, 18 Jan 2013 05:10:24 +0000 (00:10 -0500)
Lib/test/test_signal.py
Misc/NEWS
Modules/signalmodule.c

index 28037858b02c1c54c0b8a58ca59d9607a8047593..fa06729b6ea57cdb725c1d0caf8dd3f985ebe13a 100644 (file)
@@ -227,6 +227,13 @@ class WindowsSignalTests(unittest.TestCase):
             signal.signal(7, handler)
 
 
+class WakeupFDTests(unittest.TestCase):
+
+    def test_invalid_fd(self):
+        fd = support.make_bad_fd()
+        self.assertRaises(ValueError, signal.set_wakeup_fd, fd)
+
+
 @unittest.skipIf(sys.platform == "win32", "Not valid on Windows")
 class WakeupSignalTests(unittest.TestCase):
     TIMEOUT_FULL = 10
@@ -485,8 +492,9 @@ class ItimerTest(unittest.TestCase):
 
 def test_main():
     test_support.run_unittest(BasicSignalTests, InterProcessSignalTests,
-                              WakeupSignalTests, SiginterruptTest,
-                              ItimerTest, WindowsSignalTests)
+                              WakeupFDTests, WakeupSignalTests,
+                              SiginterruptTest, ItimerTest,
+                              WindowsSignalTests)
 
 
 if __name__ == "__main__":
index eb41458e82753b9cf9008b029ac2164dd306e2c7..f7491d1843e8a98a5f65c232e8fd30e1f39bcb84 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -189,6 +189,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #16992: On Windows in signal.set_wakeup_fd, validate the file
+  descriptor argument.
+
 - Issue #15861: tkinter now correctly works with lists and tuples containing
   strings with whitespaces, backslashes or unbalanced braces.
 
index f706a8fd8f359adc880929dd1fad3d2859680126..d5d628328b1477cfe2a86a2091539391eec75b42 100644 (file)
@@ -407,7 +407,7 @@ signal_set_wakeup_fd(PyObject *self, PyObject *args)
         return NULL;
     }
 #endif
-    if (fd != -1 && fstat(fd, &buf) != 0) {
+    if (fd != -1 && (!_PyVerify_fd(fd) || fstat(fd, &buf) != 0)) {
         PyErr_SetString(PyExc_ValueError, "invalid fd");
         return NULL;
     }