diff options
author | Benjamin Peterson <benjamin@python.org> | 2015-02-14 15:16:32 -0500 |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2015-02-14 15:16:32 -0500 |
commit | 0960a8c08ce3f639e3ee3232e1df017014a31e86 (patch) | |
tree | a6b270e7c3758db179e20b0d8c47110d27c92d68 /Python/frozenmain.c | |
parent | b534aba33871914c5090bcb366205ca80fd37cc9 (diff) | |
download | cpython-0960a8c08ce3f639e3ee3232e1df017014a31e86.tar.gz |
avoid reading unallocated memory when argc == 0 (closes #22633)
Diffstat (limited to 'Python/frozenmain.c')
-rw-r--r-- | Python/frozenmain.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/Python/frozenmain.c b/Python/frozenmain.c index 55d05fc26f..b05c94a7e1 100644 --- a/Python/frozenmain.c +++ b/Python/frozenmain.c @@ -24,11 +24,13 @@ Py_FrozenMain(int argc, char **argv) /* We need a second copies, as Python might modify the first one. */ wchar_t **argv_copy2 = NULL; - argv_copy = PyMem_RawMalloc(sizeof(wchar_t*) * argc); - argv_copy2 = PyMem_RawMalloc(sizeof(wchar_t*) * argc); - if (!argv_copy || !argv_copy2) { - fprintf(stderr, "out of memory\n"); - goto error; + if (argc > 0) { + argv_copy = PyMem_RawMalloc(sizeof(wchar_t*) * argc); + argv_copy2 = PyMem_RawMalloc(sizeof(wchar_t*) * argc); + if (!argv_copy || !argv_copy2) { + fprintf(stderr, "out of memory\n"); + goto error; + } } Py_FrozenFlag = 1; /* Suppress errors from getpath.c */ @@ -68,7 +70,8 @@ Py_FrozenMain(int argc, char **argv) #ifdef MS_WINDOWS PyInitFrozenExtensions(); #endif /* MS_WINDOWS */ - Py_SetProgramName(argv_copy[0]); + if (argc >= 1) + Py_SetProgramName(argv_copy[0]); Py_Initialize(); #ifdef MS_WINDOWS PyWinFreeze_ExeInit(); |