Skip to content

Commit

Permalink
bpo-37926: Fix PySys_SetArgvEx(0, NULL, 0) crash (pythonGH-15415)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vstinner authored and lisroach committed Sep 9, 2019
1 parent 90d3356 commit c772420
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
@@ -0,0 +1 @@
Fix a crash in ``PySys_SetArgvEx(0, NULL, 0)``.
2 changes: 1 addition & 1 deletion Python/sysmodule.c
Expand Up @@ -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;
}
Expand Down

0 comments on commit c772420

Please sign in to comment.