Mercurial > cpython-lru_cache-weakref
diff Modules/python.c @ 75944:c0900fd6e4b3 3.2
Issue #3367: NULL-terminate argv[] copies to prevent an invalid access
in sys_update_path().
| author | Stefan Krah <skrah@bytereef.org> |
|---|---|
| date | Mon, 26 Mar 2012 15:05:22 +0200 |
| parents | 3b17210f34d9 |
| children | c838c9b117f1 f77998006917 |
line wrap: on
line diff
--- a/Modules/python.c Sun Mar 25 22:41:06 2012 -0400 +++ b/Modules/python.c Mon Mar 26 15:05:22 2012 +0200 @@ -22,9 +22,9 @@ int main(int argc, char **argv) { - wchar_t **argv_copy = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*argc); + wchar_t **argv_copy = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*(argc+1)); /* We need a second copies, as Python might modify the first one. */ - wchar_t **argv_copy2 = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*argc); + wchar_t **argv_copy2 = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*(argc+1)); int i, res; char *oldloc; /* 754 requires that FP exceptions run in "no stop" mode by default, @@ -58,6 +58,8 @@ } argv_copy2[i] = argv_copy[i]; } + argv_copy2[argc] = argv_copy[argc] = NULL; + setlocale(LC_ALL, oldloc); free(oldloc); res = Py_Main(argc, argv_copy);
