From: Victor Stinner Date: Wed, 7 Apr 2021 21:12:45 +0000 (+0200) Subject: bpo-42923: Fix _Py_DumpExtensionModules() for NULL sysdict (GH-25262) X-Git-Tag: v3.10.0b1~370 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3d55aa9e7365af76e40680271328deece27a7339;p=thirdparty%2FPython%2Fcpython.git bpo-42923: Fix _Py_DumpExtensionModules() for NULL sysdict (GH-25262) Fix Py_FatalError() is called before interp->sysdict is set. --- diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 64723ce82d76..0ad1796e3cbc 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,