Commit 2476b98a authored by Benjamin Peterson's avatar Benjamin Peterson

avoid reading unallocated memory when argc == 0 (closes #22633)

parent 366c570d
...@@ -24,12 +24,14 @@ Py_FrozenMain(int argc, char **argv) ...@@ -24,12 +24,14 @@ Py_FrozenMain(int argc, char **argv)
/* We need a second copies, as Python might modify the first one. */ /* We need a second copies, as Python might modify the first one. */
wchar_t **argv_copy2 = NULL; wchar_t **argv_copy2 = NULL;
if (argc > 0) {
argv_copy = PyMem_RawMalloc(sizeof(wchar_t*) * argc); argv_copy = PyMem_RawMalloc(sizeof(wchar_t*) * argc);
argv_copy2 = PyMem_RawMalloc(sizeof(wchar_t*) * argc); argv_copy2 = PyMem_RawMalloc(sizeof(wchar_t*) * argc);
if (!argv_copy || !argv_copy2) { if (!argv_copy || !argv_copy2) {
fprintf(stderr, "out of memory\n"); fprintf(stderr, "out of memory\n");
goto error; goto error;
} }
}
Py_FrozenFlag = 1; /* Suppress errors from getpath.c */ Py_FrozenFlag = 1; /* Suppress errors from getpath.c */
...@@ -68,6 +70,7 @@ Py_FrozenMain(int argc, char **argv) ...@@ -68,6 +70,7 @@ Py_FrozenMain(int argc, char **argv)
#ifdef MS_WINDOWS #ifdef MS_WINDOWS
PyInitFrozenExtensions(); PyInitFrozenExtensions();
#endif /* MS_WINDOWS */ #endif /* MS_WINDOWS */
if (argc >= 1)
Py_SetProgramName(argv_copy[0]); Py_SetProgramName(argv_copy[0]);
Py_Initialize(); Py_Initialize();
#ifdef MS_WINDOWS #ifdef MS_WINDOWS
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment