https://github.com/python/cpython/commit/3403de5283fd44bba842638414e07999e0449723
commit: 3403de5283fd44bba842638414e07999e0449723
branch: main
author: sobolevn <[email protected]>
committer: sobolevn <[email protected]>
date: 2026-11-14T23:30:23+03:00
summary:

gh-161863: Fix possible `NULL` deref in `_PyErr_Display` (#161979)

files:
M Python/pythonrun.c

diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 5e026a93d5c180..38003e60e985ca 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -1157,6 +1157,13 @@ _PyErr_Display(PyObject *file, PyObject *unused, 
PyObject *value, PyObject *tb)
         }
     }
 
+    // gh-161863: Interpreter can be not fully initialized
+    // when calling this function. May be not safe to call the import.
+    PyInterpreterState *interp = _PyInterpreterState_GET();
+    if (interp->imports.importlib == NULL) {
+        goto fallback;
+    }
+
     // Try first with the stdlib traceback module
     PyObject *print_exception_fn = PyImport_ImportModuleAttrString(
         "traceback",

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to