Skip to content

Commit 3403de5

Browse files
authored
gh-161863: Fix possible NULL deref in _PyErr_Display (#161979)
1 parent b968417 commit 3403de5

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

‎Python/pythonrun.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,13 @@ _PyErr_Display(PyObject *file, PyObject *unused, PyObject *value, PyObject *tb)
11571157
}
11581158
}
11591159

1160+
// gh-161863: Interpreter can be not fully initialized
1161+
// when calling this function. May be not safe to call the import.
1162+
PyInterpreterState *interp = _PyInterpreterState_GET();
1163+
if (interp->imports.importlib == NULL) {
1164+
goto fallback;
1165+
}
1166+
11601167
// Try first with the stdlib traceback module
11611168
PyObject *print_exception_fn = PyImport_ImportModuleAttrString(
11621169
"traceback",

0 commit comments

Comments
 (0)