summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2013-01-18 05:10:24 (GMT)
committerBenjamin Peterson <benjamin@python.org>2013-01-18 05:10:24 (GMT)
commitc68a4a048cf4e2d520b00546d8a4eef3a2723e8b (patch)
treec2da8094f7a98fa39f2acd34af343b99c2c49861
parentfc4aa76d59968a60ea91bda4b2c505e1070743ac (diff)
downloadcpython-c68a4a048cf4e2d520b00546d8a4eef3a2723e8b.zip
cpython-c68a4a048cf4e2d520b00546d8a4eef3a2723e8b.tar.gz
cpython-c68a4a048cf4e2d520b00546d8a4eef3a2723e8b.tar.bz2
check windows fd validity (closes #16992)
-rw-r--r--Lib/test/test_signal.py11
-rw-r--r--Misc/NEWS3
-rw-r--r--Modules/signalmodule.c2
3 files changed, 13 insertions, 3 deletions
diff --git a/Lib/test/test_signal.py b/Lib/test/test_signal.py
index e87900a..99243df 100644
--- a/Lib/test/test_signal.py
+++ b/Lib/test/test_signal.py
@@ -222,6 +222,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):
def check_wakeup(self, test_body, *signals, ordered=True):
@@ -864,8 +871,8 @@ class PendingSignalsTests(unittest.TestCase):
def test_main():
try:
support.run_unittest(PosixTests, InterProcessSignalTests,
- WakeupSignalTests, SiginterruptTest,
- ItimerTest, WindowsSignalTests,
+ WakeupFDTests, WakeupSignalTests,
+ SiginterruptTest, ItimerTest, WindowsSignalTests,
PendingSignalsTests)
finally:
support.reap_children()
diff --git a/Misc/NEWS b/Misc/NEWS
index 11fa1f3..d7e01a7 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -150,6 +150,9 @@ Core and Builtins
Library
-------
+- Issue #16992: On Windows in signal.set_wakeup_fd, validate the file
+ descriptor argument.
+
- Issue #16422: For compatibility with the Python version, the C version of
decimal now uses strings instead of integers for rounding mode constants.
diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c
index eb89a03..0aac98b 100644
--- a/Modules/signalmodule.c
+++ b/Modules/signalmodule.c
@@ -427,7 +427,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;
}