Skip to content

Commit 48a583b

Browse files
Issue #25698: Prevent possible replacing imported module with the empty one
if the stack is too deep.
1 parent c04fb56 commit 48a583b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Python/import.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,9 +671,13 @@ PyImport_AddModuleObject(PyObject *name)
671671
PyObject *modules = PyImport_GetModuleDict();
672672
PyObject *m;
673673

674-
if ((m = PyDict_GetItem(modules, name)) != NULL &&
675-
PyModule_Check(m))
674+
if ((m = PyDict_GetItemWithError(modules, name)) != NULL &&
675+
PyModule_Check(m)) {
676676
return m;
677+
}
678+
if (PyErr_Occurred()) {
679+
return NULL;
680+
}
677681
m = PyModule_NewObject(name);
678682
if (m == NULL)
679683
return NULL;

0 commit comments

Comments
 (0)