Skip to content

Commit ca9ae94

Browse files
authored
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 c486825)
1 parent 994925b commit ca9ae94

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3080,9 +3080,10 @@ make_sys_argv(int argc, wchar_t * const * argv)
30803080
void
30813081
PySys_SetArgvEx(int argc, wchar_t **argv, int updatepath)
30823082
{
3083+
wchar_t* empty_argv[1] = {L""};
3084+
30833085
if (argc < 1 || argv == NULL) {
30843086
/* Ensure at least one (empty) argument is seen */
3085-
wchar_t* empty_argv[1] = {L""};
30863087
argv = empty_argv;
30873088
argc = 1;
30883089
}

0 commit comments

Comments
 (0)