bpo-36301: _PyCoreConfig_Read() ensures that argv is not empty (GH-12347)

If argv is empty, add an empty string.
This commit is contained in:
Victor Stinner 2019-03-15 16:03:23 +01:00 committed by GitHub
parent 74f6568bbd
commit 625997622b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View File

@ -292,7 +292,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
'pycache_prefix': None, 'pycache_prefix': None,
'program_name': './_testembed', 'program_name': './_testembed',
'argv': [], 'argv': [""],
'program': None, 'program': None,
'xoptions': [], 'xoptions': [],

View File

@ -1464,6 +1464,13 @@ _PyCoreConfig_Read(_PyCoreConfig *config, const _PyPreConfig *preconfig)
return err; return err;
} }
if (config->argv.length < 1) {
/* Ensure at least one (empty) argument is seen */
if (_PyWstrList_Append(&config->argv, L"") < 0) {
return _Py_INIT_NO_MEMORY();
}
}
assert(config->preconfig.use_environment >= 0); assert(config->preconfig.use_environment >= 0);
assert(config->filesystem_encoding != NULL); assert(config->filesystem_encoding != NULL);
assert(config->filesystem_errors != NULL); assert(config->filesystem_errors != NULL);