[Python-checkins] cpython: Fix potential NULL pointer dereference in _imp_create_builtin

christian.heimes python-checkins at python.org
Thu Sep 8 18:34:02 EDT 2016


https://hg.python.org/cpython/rev/4af9d196cd21
changeset:   103379:4af9d196cd21
user:        Christian Heimes <christian at python.org>
date:        Fri Sep 09 00:25:03 2016 +0200
summary:
  Fix potential NULL pointer dereference in _imp_create_builtin
PyModule_GetDef() can return NULL. Let's check the return value properly
like in the other five cases.

CID 1299590

files:
  Python/import.c |  4 ++++
  1 files changed, 4 insertions(+), 0 deletions(-)


diff --git a/Python/import.c b/Python/import.c
--- a/Python/import.c
+++ b/Python/import.c
@@ -1077,6 +1077,10 @@
             } else {
                 /* Remember pointer to module init function. */
                 def = PyModule_GetDef(mod);
+                if (def == NULL) {
+                    Py_DECREF(name);
+                    return NULL;
+                }
                 def->m_base.m_init = p->initfunc;
                 if (_PyImport_FixupExtensionObject(mod, name, name) < 0) {
                     Py_DECREF(name);

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


More information about the Python-checkins mailing list