bpo-45445: Fail if an invalid X-option is provided in the command line (GH-28823)

This commit is contained in:
Pablo Galindo Salgado 2021-10-13 18:08:19 +01:00 committed by GitHub
parent 1c83135381
commit db2b6a20cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 88 additions and 27 deletions

View file

@ -211,7 +211,7 @@ static int test_pre_initialization_sys_options(void)
* relying on the caller to keep the passed in strings alive.
*/
const wchar_t *static_warnoption = L"once";
const wchar_t *static_xoption = L"also_not_an_option=2";
const wchar_t *static_xoption = L"utf8=1";
size_t warnoption_len = wcslen(static_warnoption);
size_t xoption_len = wcslen(static_xoption);
wchar_t *dynamic_once_warnoption = \
@ -230,7 +230,7 @@ static int test_pre_initialization_sys_options(void)
PySys_AddWarnOption(L"module");
PySys_AddWarnOption(L"default");
_Py_EMBED_PREINIT_CHECK("Checking PySys_AddXOption\n");
PySys_AddXOption(L"not_an_option=1");
PySys_AddXOption(L"dev=2");
PySys_AddXOption(dynamic_xoption);
/* Delete the dynamic options early */
@ -548,7 +548,7 @@ static int test_init_from_config(void)
L"-W",
L"cmdline_warnoption",
L"-X",
L"cmdline_xoption",
L"dev",
L"-c",
L"pass",
L"arg2",
@ -556,10 +556,9 @@ static int test_init_from_config(void)
config_set_argv(&config, Py_ARRAY_LENGTH(argv), argv);
config.parse_argv = 1;
wchar_t* xoptions[3] = {
L"config_xoption1=3",
L"config_xoption2=",
L"config_xoption3",
wchar_t* xoptions[2] = {
L"dev=3",
L"utf8",
};
config_set_wide_string_list(&config, &config.xoptions,
Py_ARRAY_LENGTH(xoptions), xoptions);
@ -1375,7 +1374,6 @@ fail:
static int test_init_sys_add(void)
{
PySys_AddXOption(L"sysadd_xoption");
PySys_AddXOption(L"faulthandler");
PySys_AddWarnOption(L"ignore:::sysadd_warnoption");
@ -1387,14 +1385,14 @@ static int test_init_sys_add(void)
L"-W",
L"ignore:::cmdline_warnoption",
L"-X",
L"cmdline_xoption",
L"utf8",
};
config_set_argv(&config, Py_ARRAY_LENGTH(argv), argv);
config.parse_argv = 1;
PyStatus status;
status = PyWideStringList_Append(&config.xoptions,
L"config_xoption");
L"dev");
if (PyStatus_Exception(status)) {
goto fail;
}