Skip to content

Commit 6259976

Browse files
authored
bpo-36301: _PyCoreConfig_Read() ensures that argv is not empty (GH-12347)
If argv is empty, add an empty string.
1 parent 74f6568 commit 6259976

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

‎Lib/test/test_embed.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
292292

293293
'pycache_prefix': None,
294294
'program_name': './_testembed',
295-
'argv': [],
295+
'argv': [""],
296296
'program': None,
297297

298298
'xoptions': [],

‎Python/coreconfig.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,6 +1464,13 @@ _PyCoreConfig_Read(_PyCoreConfig *config, const _PyPreConfig *preconfig)
14641464
return err;
14651465
}
14661466

1467+
if (config->argv.length < 1) {
1468+
/* Ensure at least one (empty) argument is seen */
1469+
if (_PyWstrList_Append(&config->argv, L"") < 0) {
1470+
return _Py_INIT_NO_MEMORY();
1471+
}
1472+
}
1473+
14671474
assert(config->preconfig.use_environment >= 0);
14681475
assert(config->filesystem_encoding != NULL);
14691476
assert(config->filesystem_errors != NULL);

0 commit comments

Comments
 (0)