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.signal(bogus_signal, handler) segfaults on Windows #53570

Closed
midnightdf mannequin opened this issue Jul 21, 2010 · 7 comments
Closed

signal.signal(bogus_signal, handler) segfaults on Windows #53570

midnightdf mannequin opened this issue Jul 21, 2010 · 7 comments
Assignees
Labels
extension-modules C modules in the Modules dir OS-windows type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@midnightdf
Copy link
Mannequin

midnightdf mannequin commented Jul 21, 2010

BPO 9324
Nosy @pfmoore, @ronaldoussoren, @briancurtin
Files
  • cpy_crash.jpg: Repro screenshot
  • issue9324.diff: py3k patch
  • issue9324_v2.diff
  • 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 = 'https://github.com/briancurtin'
    closed_at = <Date 2010-09-06.16:18:19.791>
    created_at = <Date 2010-07-21.18:50:55.139>
    labels = ['extension-modules', 'OS-windows', 'type-crash']
    title = 'signal.signal(bogus_signal, handler) segfaults on Windows'
    updated_at = <Date 2010-09-06.16:18:19.789>
    user = 'https://bugs.python.org/midnightdf'

    bugs.python.org fields:

    activity = <Date 2010-09-06.16:18:19.789>
    actor = 'brian.curtin'
    assignee = 'brian.curtin'
    closed = True
    closed_date = <Date 2010-09-06.16:18:19.791>
    closer = 'brian.curtin'
    components = ['Extension Modules', 'Windows']
    creation = <Date 2010-07-21.18:50:55.139>
    creator = 'midnightdf'
    dependencies = []
    files = ['18109', '18112', '18456']
    hgrepos = []
    issue_num = 9324
    keywords = ['patch']
    message_count = 7.0
    messages = ['111104', '111107', '111113', '111114', '113127', '113463', '115713']
    nosy_count = 7.0
    nosy_names = ['paul.moore', 'ronaldoussoren', 'gcewing', 'ocean-city', 'tlesher', 'brian.curtin', 'midnightdf']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue9324'
    versions = ['Python 3.1', 'Python 2.7', 'Python 3.2']

    @midnightdf
    Copy link
    Mannequin Author

    midnightdf mannequin commented Jul 21, 2010

    Using Python 2.7 (r27:82525, Jul 4 2010, 09:01:59; 32-bit Intel) on 64-bit Windows Server 2008 R2, python.exe (interactive sessions and files) crashes when it encounters the following snippet:
    >>> import signal
    >>> signal.signal(7, lambda a, b: None)

    Note that Python doesn't crash if I substitute '7' with a valid Windows signal (e.g., '2'). Also, it seems that at least some invalid signal inputs (e.g., '0') generate the appropriate Python exception.

    @midnightdf midnightdf mannequin added the type-crash A hard crash of the interpreter, possibly with a core dump label Jul 21, 2010
    @briancurtin briancurtin added extension-modules C modules in the Modules dir OS-windows labels Jul 21, 2010
    @tlesher
    Copy link
    Mannequin

    tlesher mannequin commented Jul 21, 2010

    This appears to run afoul of Microsoft's "security-enhanced CRT", which aborts a program that calls certain API functions (including signal) with invalid parameters.

    PyOS_getsig() has conditionally-compiled code added to deal with this (and handle invalid signal values before passing them to the CRT); PyOS_setsig() should get the same treatment.

    @briancurtin
    Copy link
    Member

    bpo-9324.diff checks the signal value after argument parsing and before sending it onward towards the system call.

    It only lets you use the following signals, per http://msdn.microsoft.com/en-us/library/xdkz3x12.aspx
    SIGABRT
    SIGFPE
    SIGILL
    SIGINT
    SIGSEGV
    SIGTERM

    @briancurtin briancurtin self-assigned this Jul 21, 2010
    @briancurtin
    Copy link
    Member

    Oops, note to myself that there's a long line in signalmodule.c.

    @briancurtin
    Copy link
    Member

    Fixed in r83763 (py3k), r83764 (release31-maint), and r83765 (release27-maint). Thanks for reporting this.

    @briancurtin
    Copy link
    Member

    Attached is a patch using Ronald's suggestion to rework this as a switch statement. Also included is a minor reworking that Paul noticed in Lib/test/test_signal.py.

    Added the people who responded to the python-dev checkin comments to the nosy list. Feel free to remove yourself.

    @briancurtin
    Copy link
    Member

    Checked in the suggested fixes in r84556 (py3k), r84557 (release27-maint), and r84558 (release27-maint).

    @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
    extension-modules C modules in the Modules dir OS-windows type-crash A hard crash of the interpreter, possibly with a core dump
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant