[Python-checkins] cpython (merge 3.5 -> default): Issue #25698: Prevent possible replacing imported module with the empty one

serhiy.storchaka python-checkins at python.org
Wed Feb 10 03:33:31 EST 2016


https://hg.python.org/cpython/rev/c711c36cf988
changeset:   100216:c711c36cf988
parent:      100212:37f6f965023d
parent:      100215:1c2de3b0a474
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Wed Feb 10 10:31:43 2016 +0200
summary:
  Issue #25698: Prevent possible replacing imported module with the empty one
if the stack is too deep.

files:
  Python/import.c |  8 ++++++--
  1 files changed, 6 insertions(+), 2 deletions(-)


diff --git a/Python/import.c b/Python/import.c
--- a/Python/import.c
+++ b/Python/import.c
@@ -671,9 +671,13 @@
     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;

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list