bpo-33706: Fix pymain_parse_cmdline_impl() (GH-7283)

https://github.com/python/cpython/commit/c6de46e180e81508a3b43341791b56418bd... commit: c6de46e180e81508a3b43341791b56418bd811f9 branch: 3.7 author: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> committer: GitHub <noreply@github.com> date: 2018-05-31T06:43:21-07:00 summary: bpo-33706: Fix pymain_parse_cmdline_impl() (GH-7283) Fix a crash in Python initialization when parsing the command line options. Fix memcpy() size parameter: previously, we read one wchar_t after the end of _PyOS_optarg. Moreover, don't copy the trailingg NUL character: we write it manually anyway. Thanks Christoph Gohlke for the bug report and the fix! (cherry picked from commit 58d1683255abb0df4fc70960da6121aeaa41e1d1) Co-authored-by: Victor Stinner <vstinner@redhat.com> files: A Misc/NEWS.d/next/Core and Builtins/2018-05-31-14-50-04.bpo-33706.ztlH04.rst M Modules/main.c diff --git a/Misc/NEWS.d/next/Core and Builtins/2018-05-31-14-50-04.bpo-33706.ztlH04.rst b/Misc/NEWS.d/next/Core and Builtins/2018-05-31-14-50-04.bpo-33706.ztlH04.rst new file mode 100644 index 000000000000..d3b8477b2197 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2018-05-31-14-50-04.bpo-33706.ztlH04.rst @@ -0,0 +1,2 @@ +Fix a crash in Python initialization when parsing the command line options. +Thanks Christoph Gohlke for the bug report and the fix! diff --git a/Modules/main.c b/Modules/main.c index 9cbb3f1ce003..286ad418fe13 100644 --- a/Modules/main.c +++ b/Modules/main.c @@ -761,7 +761,7 @@ pymain_parse_cmdline_impl(_PyMain *pymain, _Py_CommandLineDetails *cmdline) pymain->err = _Py_INIT_NO_MEMORY(); return -1; } - memcpy(command, _PyOS_optarg, len * sizeof(wchar_t)); + memcpy(command, _PyOS_optarg, (len - 2) * sizeof(wchar_t)); command[len - 2] = '\n'; command[len - 1] = 0; pymain->command = command;
participants (1)
-
Miss Islington (bot)