]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-42923: Fix _Py_DumpExtensionModules() for NULL sysdict (GH-25262)
authorVictor Stinner <vstinner@python.org>
Wed, 7 Apr 2021 21:12:45 +0000 (23:12 +0200)
committerGitHub <noreply@github.com>
Wed, 7 Apr 2021 21:12:45 +0000 (23:12 +0200)
Fix Py_FatalError() is called before interp->sysdict is set.

Python/pylifecycle.c

index 64723ce82d76c6c17fa45a7b47f650869d8cae39..0ad1796e3cbc6e7278a2c75a8e22e167b848a20f 100644 (file)
@@ -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,