]> granicus.if.org Git - python/commitdiff
Add error checking to PyInit_pyexpact
authorChristian Heimes <christian@python.org>
Thu, 8 Sep 2016 22:13:35 +0000 (00:13 +0200)
committerChristian Heimes <christian@python.org>
Thu, 8 Sep 2016 22:13:35 +0000 (00:13 +0200)
The module initializer of the pyexpat module failed to check
the return value of PySys_GetObject() for NULL.

CID 982779

Modules/pyexpat.c

index dc97e9d2bf39ff6d8d961260be708973d768d288..b19b7be160537cdb242d106008d8b475a3ef20d5 100644 (file)
@@ -1701,7 +1701,15 @@ MODULE_INITFUNC(void)
     PyModule_AddStringConstant(m, "native_encoding", "UTF-8");
 
     sys_modules = PySys_GetObject("modules");
+    if (sys_modules == NULL) {
+        Py_DECREF(m);
+        return NULL;
+    }
     d = PyModule_GetDict(m);
+    if (d == NULL) {
+        Py_DECREF(m);
+        return NULL;
+    }
     errors_module = PyDict_GetItem(d, errmod_name);
     if (errors_module == NULL) {
         errors_module = PyModule_New(MODULE_NAME ".errors");
@@ -1722,9 +1730,11 @@ MODULE_INITFUNC(void)
         }
     }
     Py_DECREF(modelmod_name);
-    if (errors_module == NULL || model_module == NULL)
+    if (errors_module == NULL || model_module == NULL) {
         /* Don't core dump later! */
+        Py_DECREF(m);
         return NULL;
+    }
 
 #if XML_COMBINED_VERSION > 19505
     {