mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
Fix #9324: Add parameter validation to signal.signal on Windows in order
to prevent crashes.
This commit is contained in:
parent
e6fc7401a9
commit
ef9efbd69c
4 changed files with 50 additions and 5 deletions
|
@ -255,8 +255,23 @@ signal_signal(PyObject *self, PyObject *args)
|
|||
int sig_num;
|
||||
PyObject *old_handler;
|
||||
void (*func)(int);
|
||||
#ifdef MS_WINDOWS
|
||||
int cur_sig, num_valid_sigs = 6;
|
||||
static int valid_sigs[] = {SIGABRT, SIGFPE, SIGILL, SIGINT,
|
||||
SIGSEGV, SIGTERM};
|
||||
BOOL valid_sig = FALSE;
|
||||
#endif
|
||||
if (!PyArg_ParseTuple(args, "iO:signal", &sig_num, &obj))
|
||||
return NULL;
|
||||
#ifdef MS_WINDOWS
|
||||
/* Validate that sig_num is one of the allowable signals */
|
||||
for (cur_sig = 0; cur_sig < num_valid_sigs; cur_sig++)
|
||||
valid_sig |= (sig_num == valid_sigs[cur_sig]);
|
||||
if (!valid_sig) {
|
||||
PyErr_SetString(PyExc_ValueError, "signal number out of range");
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
#ifdef WITH_THREAD
|
||||
if (PyThread_get_thread_ident() != main_thread) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue