diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-03-15 15:03:23 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-15 15:03:23 (GMT) |
commit | 625997622b4736e9184bdd8bf1e22a7b51be1afc (patch) | |
tree | 1e2dfbafa030e0c402636292127cbdeb5e156a6a | |
parent | 74f6568bbd3e70806ea3219e8bacb386ad802ccf (diff) | |
download | cpython-625997622b4736e9184bdd8bf1e22a7b51be1afc.zip cpython-625997622b4736e9184bdd8bf1e22a7b51be1afc.tar.gz cpython-625997622b4736e9184bdd8bf1e22a7b51be1afc.tar.bz2 |
bpo-36301: _PyCoreConfig_Read() ensures that argv is not empty (GH-12347)
If argv is empty, add an empty string.
-rw-r--r-- | Lib/test/test_embed.py | 2 | ||||
-rw-r--r-- | Python/coreconfig.c | 7 |
2 files changed, 8 insertions, 1 deletions
diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index 952bc32..374346e 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -292,7 +292,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): 'pycache_prefix': None, 'program_name': './_testembed', - 'argv': [], + 'argv': [""], 'program': None, 'xoptions': [], diff --git a/Python/coreconfig.c b/Python/coreconfig.c index 15107fa..0827376 100644 --- a/Python/coreconfig.c +++ b/Python/coreconfig.c @@ -1464,6 +1464,13 @@ _PyCoreConfig_Read(_PyCoreConfig *config, const _PyPreConfig *preconfig) 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->filesystem_encoding != NULL); assert(config->filesystem_errors != NULL); |