classification
Title: signal.signal(bogus_signal, handler) segfaults on Windows
Type: crash Stage: resolved
Components: Extension Modules, Windows Versions: Python 3.1, Python 3.2, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: brian.curtin Nosy List: brian.curtin, gcewing, midnightdf, ocean-city, pmoore, ronaldoussoren, tlesher
Priority: normal Keywords: patch

Created on 2010-07-21 18:50 by midnightdf, last changed 2010-09-06 16:18 by brian.curtin. This issue is now closed.

Files
File name Uploaded Description Edit
cpy_crash.jpg midnightdf, 2010-07-21 18:50 Repro screenshot
issue9324.diff brian.curtin, 2010-07-21 20:30 py3k patch
issue9324_v2.diff brian.curtin, 2010-08-09 20:16
Messages (7)
msg111104 - (view) Author: Dave Fugate (midnightdf) Date: 2010-07-21 18:50
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.
msg111107 - (view) Author: Tim Lesher (tlesher) * Date: 2010-07-21 19:39
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.
msg111113 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2010-07-21 20:30
issue9324.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
msg111114 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2010-07-21 20:33
Oops, note to myself that there's a long line in signalmodule.c.
msg113127 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2010-08-06 19:42
Fixed in r83763 (py3k), r83764 (release31-maint), and r83765 (release27-maint). Thanks for reporting this.
msg113463 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2010-08-09 20:16
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.
msg115713 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2010-09-06 16:18
Checked in the suggested fixes in r84556 (py3k), r84557 (release27-maint), and r84558 (release27-maint).
History
Date User Action Args
2010-09-06 16:18:19brian.curtinsetstatus: open -> closed
resolution: accepted -> fixed
messages: + msg115713

stage: patch review -> resolved
2010-08-09 20:16:33brian.curtinsetfiles: + issue9324_v2.diff

nosy: + pmoore, ronaldoussoren, gcewing, ocean-city
messages: + msg113463

resolution: fixed -> accepted
stage: resolved -> patch review
2010-08-06 19:42:29brian.curtinsetresolution: fixed
stage: patch review -> resolved
messages: + msg113127
versions: + Python 3.1
2010-07-21 20:33:50brian.curtinsetmessages: + msg111114
2010-07-21 20:30:22brian.curtinsetfiles: + issue9324.diff
messages: + msg111113

assignee: brian.curtin
keywords: + patch
stage: test needed -> patch review
2010-07-21 19:39:23tleshersetnosy: + tlesher
messages: + msg111107
2010-07-21 18:57:51brian.curtinsetnosy: + brian.curtin
stage: test needed

components: + Extension Modules, Windows
versions: + Python 3.2
2010-07-21 18:50:55midnightdfcreate