diff options
author | Victor Stinner <vstinner@python.org> | 2021-04-07 21:12:45 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-07 21:12:45 (GMT) |
commit | 3d55aa9e7365af76e40680271328deece27a7339 (patch) | |
tree | 60733d0cbfbf8caefd17047a21d2873f052dc3f0 /Python | |
parent | d27f8d2e07d31670af469ef387a37bc9e96ea8ad (diff) | |
download | cpython-3d55aa9e7365af76e40680271328deece27a7339.zip cpython-3d55aa9e7365af76e40680271328deece27a7339.tar.gz cpython-3d55aa9e7365af76e40680271328deece27a7339.tar.bz2 |
bpo-42923: Fix _Py_DumpExtensionModules() for NULL sysdict (GH-25262)
Fix Py_FatalError() is called before interp->sysdict is set.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/pylifecycle.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 64723ce..0ad1796 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -2551,12 +2551,14 @@ _Py_DumpExtensionModules(int fd, PyInterpreterState *interp) // memory cannot be allocated on the heap in a signal handler. // Iterate on the dict instead. PyObject *stdlib_module_names = NULL; - pos = 0; - while (PyDict_Next(interp->sysdict, &pos, &key, &value)) { - if (PyUnicode_Check(key) - && PyUnicode_CompareWithASCIIString(key, "stdlib_module_names") == 0) { - stdlib_module_names = value; - break; + if (interp->sysdict != NULL) { + pos = 0; + while (PyDict_Next(interp->sysdict, &pos, &key, &value)) { + if (PyUnicode_Check(key) + && PyUnicode_CompareWithASCIIString(key, "stdlib_module_names") == 0) { + stdlib_module_names = value; + break; + } } } // If we failed to get sys.stdlib_module_names or it's not a frozenset, |