]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-36301: _PyCoreConfig_Read() ensures that argv is not empty (GH-12347)
authorVictor Stinner <vstinner@redhat.com>
Fri, 15 Mar 2019 15:03:23 +0000 (16:03 +0100)
committerGitHub <noreply@github.com>
Fri, 15 Mar 2019 15:03:23 +0000 (16:03 +0100)
If argv is empty, add an empty string.

Lib/test/test_embed.py
Python/coreconfig.c

index 952bc327ddb3a0507bfc1b8d88671de740d8aed1..374346e3cc895f1dba433fda09dd5293675a1bcb 100644 (file)
@@ -292,7 +292,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
 
         'pycache_prefix': None,
         'program_name': './_testembed',
-        'argv': [],
+        'argv': [""],
         'program': None,
 
         'xoptions': [],
index 15107fa36ce9e6df23500a8c6c191ad6e93569d0..08273765098e07f5689c0df6ca96caf64397d949 100644 (file)
@@ -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);