diff options
author | 2022-10-05 23:55:28 +0200 | |
---|---|---|
committer | 2022-10-05 14:55:28 -0700 | |
commit | 98884f523d783ecd9933c1ca52d80fbbd7d6bdf5 (patch) | |
tree | cdfeaac4fefd2d749aabecc25f1b6e8f962eb38a | |
parent | [3.7] gh-97005: Update libexpat from 2.4.7 to 2.4.9 (gh-97006) (#97014) (diff) | |
download | cpython-98884f523d783ecd9933c1ca52d80fbbd7d6bdf5.tar.gz cpython-98884f523d783ecd9933c1ca52d80fbbd7d6bdf5.tar.bz2 cpython-98884f523d783ecd9933c1ca52d80fbbd7d6bdf5.zip |
[3.7] gh-96848: Fix -X int_max_str_digits option parsing (#96988) (#97576)
Fix command line parsing: reject "-X int_max_str_digits" option with
no value (invalid) when the PYTHONINTMAXSTRDIGITS environment
variable is set to a valid limit.
(cherry picked from commit 41351662bcd21672d8ccfa62fe44d72027e6bcf8)
-rw-r--r-- | Lib/test/test_cmd_line.py | 2 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Core and Builtins/2022-09-21-14-38-31.gh-issue-96848.WuoLzU.rst | 3 | ||||
-rw-r--r-- | Modules/main.c | 3 |
3 files changed, 7 insertions, 1 deletions
diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py index 0ca90fd4ab4..56455ac9dc7 100644 --- a/Lib/test/test_cmd_line.py +++ b/Lib/test/test_cmd_line.py @@ -717,6 +717,8 @@ class CmdLineTest(unittest.TestCase): assert_python_failure('-X', 'int_max_str_digits', '-c', code) assert_python_failure('-X', 'int_max_str_digits=foo', '-c', code) assert_python_failure('-X', 'int_max_str_digits=100', '-c', code) + assert_python_failure('-X', 'int_max_str_digits', '-c', code, + PYTHONINTMAXSTRDIGITS='4000') assert_python_failure('-c', code, PYTHONINTMAXSTRDIGITS='foo') assert_python_failure('-c', code, PYTHONINTMAXSTRDIGITS='100') diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-09-21-14-38-31.gh-issue-96848.WuoLzU.rst b/Misc/NEWS.d/next/Core and Builtins/2022-09-21-14-38-31.gh-issue-96848.WuoLzU.rst new file mode 100644 index 00000000000..a9b04ce87d4 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2022-09-21-14-38-31.gh-issue-96848.WuoLzU.rst @@ -0,0 +1,3 @@ +Fix command line parsing: reject :option:`-X int_max_str_digits <-X>` option +with no value (invalid) when the :envvar:`PYTHONINTMAXSTRDIGITS` environment +variable is set to a valid limit. Patch by Victor Stinner. diff --git a/Modules/main.c b/Modules/main.c index b646fe52e6b..dfb61801793 100644 --- a/Modules/main.c +++ b/Modules/main.c @@ -1813,10 +1813,10 @@ static _PyInitError config_init_int_max_str_digits(_PyCoreConfig *config) { int maxdigits; - int valid = 0; const char *env = config_get_env_var("PYTHONINTMAXSTRDIGITS"); if (env) { + int valid = 0; if (!pymain_str_to_int(env, &maxdigits)) { valid = ((maxdigits == 0) || (maxdigits >= _PY_LONG_MAX_STR_DIGITS_THRESHOLD)); } @@ -1834,6 +1834,7 @@ config_init_int_max_str_digits(_PyCoreConfig *config) const wchar_t *xoption = config_get_xoption(config, L"int_max_str_digits"); if (xoption) { const wchar_t *sep = wcschr(xoption, L'='); + int valid = 0; if (sep) { if (!pymain_wstr_to_int(sep + 1, &maxdigits)) { valid = ((maxdigits == 0) || (maxdigits >= _PY_LONG_MAX_STR_DIGITS_THRESHOLD)); |