Commit c713837e authored by Antoine Pitrou's avatar Antoine Pitrou Committed by GitHub

[2.7] bpo-30057: Fix potential missed signal in signal.signal(). (GH-4258) (#4263)

Bug report and patch by Jeroen Demeyer..
(cherry picked from commit f6f90ff0)
parent b694770a
...@@ -324,6 +324,7 @@ Vincent Delft ...@@ -324,6 +324,7 @@ Vincent Delft
Arnaud Delobelle Arnaud Delobelle
Konrad Delong Konrad Delong
Erik Demaine Erik Demaine
Jeroen Demeyer
Martin Dengler Martin Dengler
John Dennis John Dennis
L. Peter Deutsch L. Peter Deutsch
......
Fix potential missed signal in signal.signal().
...@@ -317,12 +317,15 @@ signal_signal(PyObject *self, PyObject *args) ...@@ -317,12 +317,15 @@ signal_signal(PyObject *self, PyObject *args)
} }
else else
func = signal_handler; func = signal_handler;
/* Check for pending signals before changing signal handler */
if (PyErr_CheckSignals()) {
return NULL;
}
if (PyOS_setsig(sig_num, func) == SIG_ERR) { if (PyOS_setsig(sig_num, func) == SIG_ERR) {
PyErr_SetFromErrno(PyExc_RuntimeError); PyErr_SetFromErrno(PyExc_RuntimeError);
return NULL; return NULL;
} }
old_handler = Handlers[sig_num].func; old_handler = Handlers[sig_num].func;
Handlers[sig_num].tripped = 0;
Py_INCREF(obj); Py_INCREF(obj);
Handlers[sig_num].func = obj; Handlers[sig_num].func = obj;
if (old_handler != NULL) if (old_handler != NULL)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment