Skip to content

Commit c486825

Browse files
authored
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.
1 parent d288b29 commit c486825

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a crash in ``PySys_SetArgvEx(0, NULL, 0)``.

Python/sysmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3058,11 +3058,11 @@ make_sys_argv(int argc, wchar_t * const * argv)
30583058
void
30593059
PySys_SetArgvEx(int argc, wchar_t **argv, int updatepath)
30603060
{
3061+
wchar_t* empty_argv[1] = {L""};
30613062
PyThreadState *tstate = _PyThreadState_GET();
30623063

30633064
if (argc < 1 || argv == NULL) {
30643065
/* Ensure at least one (empty) argument is seen */
3065-
wchar_t* empty_argv[1] = {L""};
30663066
argv = empty_argv;
30673067
argc = 1;
30683068
}

0 commit comments

Comments
 (0)