Browse Source

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

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.

(cherry picked from commit c48682509d)
pull/15426/head
Victor Stinner 7 years ago
committed by GitHub
parent
commit
ca9ae94a2a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      Misc/NEWS.d/next/C API/2019-08-23-11-35-55.bpo-37926.hnI5IQ.rst
  2. 3
      Python/sysmodule.c

1
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)``.

3
Python/sysmodule.c

@ -3080,9 +3080,10 @@ 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""};
if (argc < 1 || argv == NULL) {
/* Ensure at least one (empty) argument is seen */
wchar_t* empty_argv[1] = {L""};
argv = empty_argv;
argc = 1;
}

Loading…
Cancel
Save