Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0f6ce8d

Browse files
author
Stefan Krah
committed
Issue #3367: NULL-terminate argv[] copies to prevent an invalid access
in sys_update_path().
1 parent 533281d commit 0f6ce8d

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

Modules/python.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ extern wchar_t* _Py_DecodeUTF8_surrogateescape(const char *s, Py_ssize_t size);
2222
int
2323
main(int argc, char **argv)
2424
{
25-
wchar_t **argv_copy = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*argc);
25+
wchar_t **argv_copy = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*(argc+1));
2626
/* We need a second copies, as Python might modify the first one. */
27-
wchar_t **argv_copy2 = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*argc);
27+
wchar_t **argv_copy2 = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*(argc+1));
2828
int i, res;
2929
char *oldloc;
3030
/* 754 requires that FP exceptions run in "no stop" mode by default,
@@ -58,6 +58,8 @@ main(int argc, char **argv)
5858
}
5959
argv_copy2[i] = argv_copy[i];
6060
}
61+
argv_copy2[argc] = argv_copy[argc] = NULL;
62+
6163
setlocale(LC_ALL, oldloc);
6264
free(oldloc);
6365
res = Py_Main(argc, argv_copy);

0 commit comments

Comments
 (0)