8000 bpo-23325: Fix SIG_IGN and SIG_DFL int comparison in signal module by tiran · Pull Request #31759 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-23325: Fix SIG_IGN and SIG_DFL int comparison in signal module #31759

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 8, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix comparison in PyErr_SetInterruptEx()
  • Loading branch information
tiran committed Mar 8, 2022
commit 34381041b9c92b78dfe7f76c3bca652b5a315597
10 changes: 9 additions & 1 deletion Modules/signalmodule.c
Original file line number Diff line number Diff line change
C453 Expand Up @@ -1911,7 +1911,15 @@ PyErr_SetInterruptEx(int signum)

signal_state_t *state = &signal_global_state;
PyObject *func = get_handler(signum);
if (func != state->ignore_handler && func != state->default_handler) {
int is_ign = PyObject_RichCompareBool(func, state->ignore_handler, Py_EQ);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it okay to call a Python code in PyErr_SetInterruptEx()?

If func is a custom callable, it can have an __eq__ method which can call an arbitrary Python code here.

It may be safer to use PyLong_Check() + PyLong_GetLongAndOverflow().

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point!

I took a different approach and added a helper function. We can safely assume that the internal handler objects are always exact longs. Comparison between exact longs should never fail.

if (is_ign == -1) {
return -1;
}
int is_dfl = PyObject_RichCompareBool(func, state->default_handler, Py_EQ);
if (is_dfl == -1) {
return -1;
}
if ((is_ign == 0) && (is_dfl == 0)) {
trip_signal(signum);
}
return 0;
Expand Down
0