From 48a583b1d83d9c44c9dd9facb9331737518d6618 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 10 Feb 2016 10:31:20 +0200 Subject: Issue #25698: Prevent possible replacing imported module with the empty one if the stack is too deep. --- Python/import.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Python/import.c b/Python/import.c index edf030d..0b843da 100644 --- a/Python/import.c +++ b/Python/import.c @@ -671,9 +671,13 @@ PyImport_AddModuleObject(PyObject *name) PyObject *modules = PyImport_GetModuleDict(); PyObject *m; - if ((m = PyDict_GetItem(modules, name)) != NULL && - PyModule_Check(m)) + if ((m = PyDict_GetItemWithError(modules, name)) != NULL && + PyModule_Check(m)) { return m; + } + if (PyErr_Occurred()) { + return NULL; + } m = PyModule_NewObject(name); if (m == NULL) return NULL; -- cgit v0.12