]> granicus.if.org Git - python/commitdiff
Issue #29682:Possible missing NULL check in pyexpat (#573)
authorsvelankar <siddharth.velankar@gmail.com>
Thu, 9 Mar 2017 05:27:48 +0000 (00:27 -0500)
committerSerhiy Storchaka <storchaka@gmail.com>
Thu, 9 Mar 2017 05:27:48 +0000 (07:27 +0200)
Modules/pyexpat.c

index a95c3885fa2cb32a5e8b083d0aeeb7f0a0b3f35c..7f95bb80e03f58fb265eef15eedd91e1b9df50b6 100644 (file)
@@ -1312,6 +1312,13 @@ newxmlparseobject(char *encoding, char *namespace_separator, PyObject *intern)
     else {
         self->itself = XML_ParserCreate(encoding);
     }
+    if (self->itself == NULL) {
+        PyErr_SetString(PyExc_RuntimeError,
+                        "XML_ParserCreate failed");
+        Py_DECREF(self);
+        return NULL;
+    }
+
 #if ((XML_MAJOR_VERSION >= 2) && (XML_MINOR_VERSION >= 1)) || defined(XML_HAS_SET_HASH_SALT)
     /* This feature was added upstream in libexpat 2.1.0.  Our expat copy
      * has a backport of this feature where we also define XML_HAS_SET_HASH_SALT
@@ -1326,12 +1333,6 @@ newxmlparseobject(char *encoding, char *namespace_separator, PyObject *intern)
 #else
     PyObject_GC_Init(self);
 #endif
-    if (self->itself == NULL) {
-        PyErr_SetString(PyExc_RuntimeError,
-                        "XML_ParserCreate failed");
-        Py_DECREF(self);
-        return NULL;
-    }
     XML_SetUserData(self->itself, (void *)self);
 #ifdef Py_USING_UNICODE
     XML_SetUnknownEncodingHandler(self->itself,