Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c68a4a0

Browse files
committed
check windows fd validity (closes #16992)
1 parent fc4aa76 commit c68a4a0

3 files changed

Lines changed: 13 additions & 3 deletions

File tree

Lib/test/test_signal.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,13 @@ def test_issue9324(self):
222222
signal.signal(7, handler)
223223

224224

225+
class WakeupFDTests(unittest.TestCase):
226+
227+
def test_invalid_fd(self):
228+
fd = support.make_bad_fd()
229+
self.assertRaises(ValueError, signal.set_wakeup_fd, fd)
230+
231+
225232
@unittest.skipIf(sys.platform == "win32", "Not valid on Windows")
226233
class WakeupSignalTests(unittest.TestCase):
227234
def check_wakeup(self, test_body, *signals, ordered=True):
@@ -864,8 +871,8 @@ def handler(signum, frame):
864871
def test_main():
865872
try:
866873
support.run_unittest(PosixTests, InterProcessSignalTests,
867-
WakeupSignalTests, SiginterruptTest,
868-
ItimerTest, WindowsSignalTests,
874+
WakeupFDTests, WakeupSignalTests,
875+
SiginterruptTest, ItimerTest, WindowsSignalTests,
869876
PendingSignalsTests)
870877
finally:
871878
support.reap_children()

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ Core and Builtins
150150
Library
151151
-------
152152

153+
- Issue #16992: On Windows in signal.set_wakeup_fd, validate the file
154+
descriptor argument.
155+
153156
- Issue #16422: For compatibility with the Python version, the C version of
154157
decimal now uses strings instead of integers for rounding mode constants.
155158

Modules/signalmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ signal_set_wakeup_fd(PyObject *self, PyObject *args)
427427
return NULL;
428428
}
429429
#endif
430-
if (fd != -1 && fstat(fd, &buf) != 0) {
430+
if (fd != -1 && (!_PyVerify_fd(fd) || fstat(fd, &buf) != 0)) {
431431
PyErr_SetString(PyExc_ValueError, "invalid fd");
432432
return NULL;
433433
}

0 commit comments

Comments
 (0)