[Python-checkins] bpo-36301: _PyCoreConfig_Read() ensures that argv is not empty (GH-12347)

Victor Stinner webhook-mailer at python.org
Fri Mar 15 11:03:29 EDT 2019


https://github.com/python/cpython/commit/625997622b4736e9184bdd8bf1e22a7b51be1afc
commit: 625997622b4736e9184bdd8bf1e22a7b51be1afc
branch: master
author: Victor Stinner <vstinner at redhat.com>
committer: GitHub <noreply at github.com>
date: 2019-03-15T16:03:23+01:00
summary:

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

If argv is empty, add an empty string.

files:
M Lib/test/test_embed.py
M Python/coreconfig.c

diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py
index 952bc327ddb3..374346e3cc89 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 15107fa36ce9..08273765098e 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);



More information about the Python-checkins mailing list