Skip to content

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

Merged
miss-islington merged 4 commits into
python:mainfrom
tiran:bpo-23325-signal-int-cmp
Mar 8, 2022
Merged

miss-islington merged 4 commits into
python:mainfrom
tiran:bpo-23325-signal-int-cmp

Conversation

@tiran

@tiran tiran commented Mar 8, 2022 •

Copy link
Copy Markdown
Member

https://bugs.python.org/issue23325

Automerge-Triggered-By: GH:tiran

@tiran
tiran force-pushed the bpo-23325-signal-int-cmp branch from 1f535e0 to 3438104 Compare March 8, 2022 11:33
Comment thread Modules/signalmodule.c Outdated
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
Copy Markdown
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
Copy Markdown
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.

@tiran
tiran force-pushed the bpo-23325-signal-int-cmp branch from 67876c2 to cc4df05 Compare March 8, 2022 16:28
@miss-islington

Copy link
Copy Markdown
Contributor

Thanks @tiran for the PR 🌮🎉.. I'm working now to backport this PR to: 3.9, 3.10.
🐍🍒⛏🤖

@miss-islington

Copy link
Copy Markdown
Contributor

Sorry, @tiran, I could not cleanly backport this to 3.9 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker c8a47e76a391c8818bf10a282cdcd3bb5c23ebf6 3.9

@miss-islington miss-islington self-assigned this Mar 8, 2022
@bedevere-bot

Copy link
Copy Markdown

GH-31768 is a backport of this pull request to the 3.10 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 8, 2022
…ythonGH-31759)

(cherry picked from commit c8a47e7)

Co-authored-by: Christian Heimes <christian@python.org>
miss-islington added a commit that referenced this pull request Mar 8, 2022
…H-31759)

(cherry picked from commit c8a47e7)

Co-authored-by: Christian Heimes <christian@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

6 participants