Skip to content

Commit

Permalink
bpo-42923: Fix _Py_DumpExtensionModules() for NULL sysdict (GH-25262)
Browse files Browse the repository at this point in the history
Fix Py_FatalError() is called before interp->sysdict is set.
  • Loading branch information
vstinner authored Apr 7, 2021
1 parent d27f8d2 commit 3d55aa9
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions Python/pylifecycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 3d55aa9

Please sign in to comment.