[Python-checkins] bpo-37926: Fix PySys_SetArgvEx(0, NULL, 0) crash (GH-15415)

Victor Stinner webhook-mailer at python.org
Fri Aug 23 06:04:20 EDT 2019


https://github.com/python/cpython/commit/c48682509dc49b43fe914fe6c502bc390345d1c2
commit: c48682509dc49b43fe914fe6c502bc390345d1c2
branch: master
author: Victor Stinner <vstinner at redhat.com>
committer: GitHub <noreply at github.com>
date: 2019-08-23T11:04:16+01:00
summary:

bpo-37926: Fix PySys_SetArgvEx(0, NULL, 0) crash (GH-15415)

empty_argv is no longer static in Python 3.8, but it is declared in
a temporary scope, whereas argv keeps a reference to it.
empty_argv memory (allocated on the stack) is reused by
make_sys_argv() code which is inlined when using gcc -O3.

Define empty_argv in PySys_SetArgvEx() body, to ensure
that it remains valid for the whole lifetime of
the PySys_SetArgvEx() call.

files:
A Misc/NEWS.d/next/C API/2019-08-23-11-35-55.bpo-37926.hnI5IQ.rst
M Python/sysmodule.c

diff --git a/Misc/NEWS.d/next/C API/2019-08-23-11-35-55.bpo-37926.hnI5IQ.rst b/Misc/NEWS.d/next/C API/2019-08-23-11-35-55.bpo-37926.hnI5IQ.rst
new file mode 100644
index 000000000000..20185330a8f4
--- /dev/null
+++ b/Misc/NEWS.d/next/C API/2019-08-23-11-35-55.bpo-37926.hnI5IQ.rst	
@@ -0,0 +1 @@
+Fix a crash in ``PySys_SetArgvEx(0, NULL, 0)``.
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index a89ebceb66c5..738bbc826f5e 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -3058,11 +3058,11 @@ make_sys_argv(int argc, wchar_t * const * argv)
 void
 PySys_SetArgvEx(int argc, wchar_t **argv, int updatepath)
 {
+    wchar_t* empty_argv[1] = {L""};
     PyThreadState *tstate = _PyThreadState_GET();
 
     if (argc < 1 || argv == NULL) {
         /* Ensure at least one (empty) argument is seen */
-        wchar_t* empty_argv[1] = {L""};
         argv = empty_argv;
         argc = 1;
     }



More information about the Python-checkins mailing list