Skip to content
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

signal module wrongly relies on small int singletons #90566

Closed
tiran opened this issue Jan 17, 2022 · 3 comments
Closed

signal module wrongly relies on small int singletons #90566

tiran opened this issue Jan 17, 2022 · 3 comments
Labels
3.9 only security fixes 3.10 only security fixes 3.11 only security fixes extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error

Comments

@tiran
Copy link
Member

tiran commented Jan 17, 2022

BPO 46408
Nosy @tiran, @serhiy-storchaka
Superseder
  • bpo-23325: Turn SIG_DFL and SIG_IGN into functions
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2022-01-17.09:13:13.899>
    created_at = <Date 2022-01-17.09:01:28.784>
    labels = ['extension-modules', 'type-bug', '3.9', '3.10', '3.11']
    title = 'signal module wrongly relies on small int singletons'
    updated_at = <Date 2022-01-17.09:13:40.107>
    user = 'https://github.com/tiran'

    bugs.python.org fields:

    activity = <Date 2022-01-17.09:13:40.107>
    actor = 'christian.heimes'
    assignee = 'none'
    closed = True
    closed_date = <Date 2022-01-17.09:13:13.899>
    closer = 'christian.heimes'
    components = ['Extension Modules']
    creation = <Date 2022-01-17.09:01:28.784>
    creator = 'christian.heimes'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 46408
    keywords = []
    message_count = 3.0
    messages = ['410747', '410748', '410750']
    nosy_count = 2.0
    nosy_names = ['christian.heimes', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '23325'
    type = 'behavior'
    url = 'https://bugs.python.org/issue46408'
    versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

    @tiran
    Copy link
    Member Author

    tiran commented Jan 17, 2022

    The signal.signal() function directly compares PyObject *handler with PyObject *modstate->ignore_handler. This works on most platforms because they are both small ints and Python uses singletons for cached small ints.

    The assumption breaks when Python is built without small int cache or a platform has SIG_IGN / SIG_DFL that is outside the range of small int cache. The wasm32-emscripten platform uses "((void (*)(int))-2)" (4294967294) for SIG_IGN. The wrong comparison breaks several tests on WASM32. The function should use PyObject_RichCompareBool(handler, modstate->ignore_handler, Py_EQ) instead.

        if (handler == modstate->ignore_handler) {
            func = SIG_IGN;
        }
        else if (handler == modstate->default_handler) {
            func = SIG_DFL;
        }

    if (handler == modstate->ignore_handler) {
    func = SIG_IGN;
    }
    else if (handler == modstate->default_handler) {
    func = SIG_DFL;

    @tiran tiran added 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error labels Jan 17, 2022
    @serhiy-storchaka
    Copy link
    Member

    See msg234768 and bpo-23325. I propose to close this as a duplicate of bpo-23325.

    @tiran tiran closed this as completed Jan 17, 2022
    @tiran tiran closed this as completed Jan 17, 2022
    @tiran
    Copy link
    Member Author

    tiran commented Jan 17, 2022

    Yes, it's a duplicate.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes 3.10 only security fixes 3.11 only security fixes extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants