]> granicus.if.org Git - python/commitdiff
bpo-37926: Fix PySys_SetArgvEx(0, NULL, 0) crash (GH-15415)
authorVictor Stinner <vstinner@redhat.com>
Fri, 23 Aug 2019 10:04:16 +0000 (11:04 +0100)
committerGitHub <noreply@github.com>
Fri, 23 Aug 2019 10:04:16 +0000 (11:04 +0100)
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.

Misc/NEWS.d/next/C API/2019-08-23-11-35-55.bpo-37926.hnI5IQ.rst [new file with mode: 0644]
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 (file)
index 0000000..2018533
--- /dev/null
@@ -0,0 +1 @@
+Fix a crash in ``PySys_SetArgvEx(0, NULL, 0)``.
index a89ebceb66c5dfb20148f1cc115763a6d96a983d..738bbc826f5e16f11e52e66d7e18e62d9b0906b6 100644 (file)
@@ -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;
     }