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

bpo-30057: Fix potential missed signal in signal.signal(). (#4258)

Bug report and patch by Jeroen Demeyer.
parent a7723d8b
...@@ -362,6 +362,7 @@ Vincent Delft ...@@ -362,6 +362,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().
...@@ -461,12 +461,15 @@ signal_signal_impl(PyObject *module, int signalnum, PyObject *handler) ...@@ -461,12 +461,15 @@ signal_signal_impl(PyObject *module, int signalnum, PyObject *handler)
} }
else else
func = signal_handler; func = signal_handler;
/* Check for pending signals before changing signal handler */
if (PyErr_CheckSignals()) {
return NULL;
}
if (PyOS_setsig(signalnum, func) == SIG_ERR) { if (PyOS_setsig(signalnum, func) == SIG_ERR) {
PyErr_SetFromErrno(PyExc_OSError); PyErr_SetFromErrno(PyExc_OSError);
return NULL; return NULL;
} }
old_handler = Handlers[signalnum].func; old_handler = Handlers[signalnum].func;
_Py_atomic_store_relaxed(&Handlers[signalnum].tripped, 0);
Py_INCREF(handler); Py_INCREF(handler);
Handlers[signalnum].func = handler; Handlers[signalnum].func = handler;
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