This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: spawnl crash on windows7
Type: crash Stage: resolved
Components: Interpreter Core, Windows Versions: Python 3.7, Python 3.6, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: steve.dower Nosy List: eryksun, paul.moore, python-dev, srinim, steve.dower, tim.golden, vstinner, zach.ware
Priority: normal Keywords:

Created on 2016-11-18 11:22 by srinim, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (13)
msg281095 - (view) Author: srinivasaraoMaddukuri (srinim) Date: 2016-11-18 11:22
in window7  (using python 3.4.3,3.5.2) following script crashes

import os
os.spawnl( os.P_NOWAIT, 'C:/Tcl/bin/tclsh.exe' )"

Note: similar issue is already exist https://bugs.python.org/issue8036
msg281096 - (view) Author: srinivasaraoMaddukuri (srinim) Date: 2016-11-18 11:24
small correction (removed " )

import os
os.spawnl( os.P_NOWAIT, 'C:/Tcl/bin/tclsh.exe' )
msg281097 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2016-11-18 11:25
Just to make sure: a crash means that the Python process is killed and you get a popup or something like that?

Can you please try to run the script on Python 3.6 using:

python.exe -X faulthandler script.py

It should display the Windows error code at least.
msg281111 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2016-11-18 12:55
spawnl is implemented by calling _spawnv [1], which is documented to invoke the invalid parameter handler if argv points to a NULL pointer. It wants the program name, or whatever, as long as argv[0] isn't NULL or an empty string, e.g. `os.spawnl(os.P_NOWAIT, 'C:/Tcl/bin/tclsh.exe', 'tclsh')`. 

The invalid parameter handler should be disabled (_Py_BEGIN_SUPPRESS_IPH) when calling _spawnv[e], which in this case would lead to an EINVAL OSError instead of crashing the process. 

For example:

    import os, sys
    from ctypes import *

    ucrt = CDLL('ucrtbase')

    @CFUNCTYPE(None, c_wchar_p, c_wchar_p, c_wchar_p, c_int, c_void_p)
    def iph(*args):
        pass

    ucrt._set_thread_local_invalid_parameter_handler(iph)

    >>> os.spawnl(os.P_NOWAIT, sys.executable)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "C:\Program Files\Python35\lib\os.py", line 977, in spawnl
        return spawnv(mode, file, args)
    OSError: [Errno 22] Invalid argument

Also, in this case a descriptive ValueError would be friendlier, given an empty argv or argv[0] that's an empty string -- at least on Windows.

[1]: https://msdn.microsoft.com/en-us/library/7zt1y878.aspx
msg281116 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2016-11-18 13:31
I like the idea of using _Py_BEGIN_SUPPRESS_IPH, but also the idea of
implementing most obvious checks on arguments. Sadly, I don't have
access to Windows yet to write such patch. Eryk, if you write such
patch, I would be happy to review it ;-) Especially if it includes
unit tests :-D
msg281181 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2016-11-18 23:50
Looks like a few functions in os module need this. os_execve_impl also doesn't release the GIL at any point, but I don't see why it shouldn't.

I'll try and get to this over the weekend if nobody else comes up with a patch first.
msg281239 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-11-20 02:42
New changeset 02f416441def by Steve Dower in branch '3.5':
Issue #28732: Fix crash in os.spawnv() with no elements in args
https://hg.python.org/cpython/rev/02f416441def
msg281240 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2016-11-20 02:51
A ValueError should also be raised when argv[0] is an empty string.
msg281241 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-11-20 02:53
New changeset 1a9e4b465497 by Steve Dower in branch '3.6':
Issue #28732: Raise ValueError when os.spawn*() is passed an empty tuple of arguments
https://hg.python.org/cpython/rev/1a9e4b465497

New changeset 75824899f0dd by Steve Dower in branch 'default':
Issue #28732: Raise ValueError when os.spawn*() is passed an empty tuple of arguments
https://hg.python.org/cpython/rev/75824899f0dd
msg281242 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-11-20 03:18
New changeset e076ace7b0ff by Steve Dower in branch '3.5':
Issue #28732: Raise ValueError when argv[0] is empty.
https://hg.python.org/cpython/rev/e076ace7b0ff

New changeset af78b33704af by Steve Dower in branch '3.6':
Issue #28732: Raise ValueError when argv[0] is empty
https://hg.python.org/cpython/rev/af78b33704af

New changeset fc6f757e53de by Steve Dower in branch 'default':
Issue #28732: Raise ValueError when argv[0] is empty
https://hg.python.org/cpython/rev/fc6f757e53de
msg281243 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2016-11-20 03:19
> ValueError should also be raised when argv[0] is an empty string.

Added that too.

Python 3.5 is missing the tests for these functions completely, so I only added those to 3.6 and later. Also the original issue was already resolved in 3.6, but I tidied up a few other functions that were missing proper handling.
msg281246 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-11-20 04:12
New changeset 2e1fb851dfb4 by Steve Dower in branch '3.6':
Issue #28732: Adds new errors to spawnv emulation for platforms that only have fork and execv
https://hg.python.org/cpython/rev/2e1fb851dfb4

New changeset ac6de11fbd50 by Steve Dower in branch 'default':
Issue #28732: Adds new errors to spawnv emulation for platforms that only have fork and execv
https://hg.python.org/cpython/rev/ac6de11fbd50
msg281248 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2016-11-20 05:40
Buildbots seem to be happy now so I'm closing the issue.

Feel free to reopen if anyone spots anything in commit review.
History
Date User Action Args
2022-04-11 14:58:39adminsetgithub: 72918
2016-11-20 05:40:20steve.dowersetstatus: open -> closed
resolution: fixed
messages: + msg281248

stage: commit review -> resolved
2016-11-20 04:12:22python-devsetmessages: + msg281246
2016-11-20 03:19:41steve.dowersetmessages: + msg281243
stage: commit review
2016-11-20 03:18:00python-devsetmessages: + msg281242
2016-11-20 02:53:47python-devsetmessages: + msg281241
2016-11-20 02:51:44eryksunsetmessages: + msg281240
2016-11-20 02:42:08python-devsetnosy: + python-dev
messages: + msg281239
2016-11-20 02:10:43steve.dowersetassignee: steve.dower
versions: + Python 3.6, Python 3.7, - Python 3.4
2016-11-18 23:50:48steve.dowersetmessages: + msg281181
2016-11-18 13:31:05vstinnersetmessages: + msg281116
2016-11-18 12:55:29eryksunsetnosy: + eryksun
messages: + msg281111
2016-11-18 11:26:55vstinnersetnosy: + paul.moore, tim.golden, zach.ware, steve.dower
components: + Windows
2016-11-18 11:25:08vstinnersetnosy: + vstinner
messages: + msg281097
2016-11-18 11:24:04srinimsetmessages: + msg281096
2016-11-18 11:22:35srinimcreate