Skip to content

Commit e84e5c6

Browse files
[3.14] gh-161863: Fix possible NULL deref in _PyErr_Display (GH-161979) (#162019)
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 da3378a commit e84e5c6

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
@@ -1155,6 +1155,13 @@ _PyErr_Display(PyObject *file, PyObject *unused, PyObject *value, PyObject *tb)
11551155
}
11561156
}
11571157

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

0 commit comments

Comments
 (0)