Skip to content

Commit 1ba9dc0

Browse files
[3.15] gh-161863: Fix possible NULL deref in _PyErr_Display (GH-161979) (#162018)
gh-161863: Fix possible `NULL` deref in `_PyErr_Display` (GH-161979) (cherry picked from commit 3403de5) Co-authored-by: sobolevn <mail@sobolevn.me>
1 parent 369e38e commit 1ba9dc0

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
@@ -1149,6 +1149,13 @@ _PyErr_Display(PyObject *file, PyObject *unused, PyObject *value, PyObject *tb)
11491149
}
11501150
}
11511151

1152+
// gh-161863: Interpreter can be not fully initialized
1153+
// when calling this function. May be not safe to call the import.
1154+
PyInterpreterState *interp = _PyInterpreterState_GET();
1155+
if (interp->imports.importlib == NULL) {
1156+
goto fallback;
1157+
}
1158+
11521159
// Try first with the stdlib traceback module
11531160
PyObject *print_exception_fn = PyImport_ImportModuleAttrString(
11541161
"traceback",

0 commit comments

Comments
 (0)