Commits

Christian Heimes  committed 8d56e34

with proper error checking

  • Participants
  • Parent commits bf31b25

Comments (0)

Files changed (10)

File Modules26/_elementtree.c

 
 #ifdef XML_BOMB_PROTECTION
     if (indirections == NULL || indirections == Py_None) {
-        EXPAT(GetFeatureDefault)(XML_FEATURE_MAX_ENTITY_INDIRECTIONS,
-                                 &max_indirections);
+        if (!EXPAT(GetFeatureDefault)(XML_FEATURE_MAX_ENTITY_INDIRECTIONS,
+                                      &max_indirections)) {
+            return PyErr_SetFromErrno(PyExc_ValueError);
+        }
     }
     else {
         max_indirections = PyLong_AsLong(indirections);
     }
 
     if (expansions == NULL || expansions == Py_None) {
-        EXPAT(GetFeatureDefault)(XML_FEATURE_MAX_ENTITY_EXPANSIONS,
-                                 &max_expansions);
+        if (!EXPAT(GetFeatureDefault)(XML_FEATURE_MAX_ENTITY_EXPANSIONS,
+                                      &max_expansions)) {
+            return PyErr_SetFromErrno(PyExc_ValueError);
+        }
     }
     else {
         max_expansions = PyLong_AsLong(expansions);
     }
 
     if (ignore_dtd == NULL) {
-        EXPAT(GetFeatureDefault)(XML_FEATURE_RESET_DTD,
-                                 &ignore_dtd_flag);
+        if (!EXPAT(GetFeatureDefault)(XML_FEATURE_RESET_DTD,
+                                      &ignore_dtd_flag)) {
+            return PyErr_SetFromErrno(PyExc_ValueError);
+        }
     }
     else if ((ignore_dtd_flag = PyObject_IsTrue(ignore_dtd)) == -1) {
              return NULL;
     }
 
 #ifdef XML_BOMB_PROTECTION
-    EXPAT(SetFeature)(self->parser, XML_FEATURE_MAX_ENTITY_INDIRECTIONS,
-                      max_indirections);
-    EXPAT(SetFeature)(self->parser, XML_FEATURE_MAX_ENTITY_EXPANSIONS,
-                      max_expansions);
-    EXPAT(SetFeature)(self->parser, XML_FEATURE_RESET_DTD,
-                      ignore_dtd_flag);
+    if (!EXPAT(SetFeature)(self->parser,
+                           XML_FEATURE_MAX_ENTITY_INDIRECTIONS,
+                           max_indirections)) {
+        return PyErr_SetFromErrno(PyExc_ValueError);
+    }
+    if (!EXPAT(SetFeature)(self->parser,
+                           XML_FEATURE_MAX_ENTITY_EXPANSIONS,
+                           max_expansions)) {
+        return PyErr_SetFromErrno(PyExc_ValueError);
+    }
+    if (!EXPAT(SetFeature)(self->parser,
+                           XML_FEATURE_RESET_DTD,
+                           ignore_dtd_flag)) {
+        return PyErr_SetFromErrno(PyExc_ValueError);
+    }
 #endif
 
     /* setup target handlers */

File Modules26/pyexpat.c

     if (name[0] == 'm') {
         if (strcmp(name, "max_entity_indirections") == 0) {
             long value = -1;
-            XML_GetFeature(self->itself, XML_FEATURE_MAX_ENTITY_INDIRECTIONS,
-                           &value);
+            if (!XML_GetFeature(self->itself,
+                                XML_FEATURE_MAX_ENTITY_INDIRECTIONS,
+                                &value)) {
+                return PyErr_SetFromErrno(PyExc_ValueError);
+            }
             return PyInt_FromLong(value);
         }
         if (strcmp(name, "max_entity_expansions") == 0) {
             long value = -1;
-            XML_GetFeature(self->itself, XML_FEATURE_MAX_ENTITY_EXPANSIONS,
-                           &value);
+            if (!XML_GetFeature(self->itself,
+                                XML_FEATURE_MAX_ENTITY_EXPANSIONS,
+                                &value)) {
+                return PyErr_SetFromErrno(PyExc_ValueError);
+            }
             return PyInt_FromLong(value);
         }
     }
 #ifdef XML_BOMB_PROTECTION
     if (strcmp(name, "reset_dtd") == 0) {
         long value = -1;
-        XML_GetFeature(self->itself, XML_FEATURE_RESET_DTD, &value);
+        if (!XML_GetFeature(self->itself, XML_FEATURE_RESET_DTD, &value)) {
+            return PyErr_SetFromErrno(PyExc_ValueError);
+        }
         return PyBool_FromLong(value);
     }
 #endif
                          UINT_MAX);
             return -1;
         }
-        XML_SetFeature(self->itself, XML_FEATURE_MAX_ENTITY_EXPANSIONS,
-                       value);
+        if (!XML_SetFeature(self->itself,
+                            XML_FEATURE_MAX_ENTITY_EXPANSIONS,
+                            value)) {
+            PyErr_SetFromErrno(PyExc_ValueError);
+            return -1;
+        }
         return 0;
     }
 
                          UINT_MAX);
             return -1;
         }
-        XML_SetFeature(self->itself, XML_FEATURE_MAX_ENTITY_INDIRECTIONS,
-                       value);
+        if (!XML_SetFeature(self->itself,
+                            XML_FEATURE_MAX_ENTITY_INDIRECTIONS,
+                            value)) {
+            PyErr_SetFromErrno(PyExc_ValueError);
+            return -1;
+        }
         return 0;
     }
 
         if ((value = PyObject_IsTrue(v)) == -1) {
             return -1;
         }
-        XML_SetFeature(self->itself, XML_FEATURE_RESET_DTD,
-                       value ? XML_TRUE : XML_FALSE);
+        if (!XML_SetFeature(self->itself, XML_FEATURE_RESET_DTD,
+                            value ? XML_TRUE : XML_FALSE)) {
+            PyErr_SetFromErrno(PyExc_ValueError);
+            return -1;
+        }
         return 0;
     }
 #endif

File Modules27/_elementtree.c

 
 #ifdef XML_BOMB_PROTECTION
     if (indirections == NULL || indirections == Py_None) {
-        EXPAT(GetFeatureDefault)(XML_FEATURE_MAX_ENTITY_INDIRECTIONS,
-                                 &max_indirections);
+        if (!EXPAT(GetFeatureDefault)(XML_FEATURE_MAX_ENTITY_INDIRECTIONS,
+                                      &max_indirections)) {
+            return PyErr_SetFromErrno(PyExc_ValueError);
+        }
     }
     else {
         max_indirections = PyLong_AsLong(indirections);
     }
 
     if (expansions == NULL || expansions == Py_None) {
-        EXPAT(GetFeatureDefault)(XML_FEATURE_MAX_ENTITY_EXPANSIONS,
-                                 &max_expansions);
+        if (!EXPAT(GetFeatureDefault)(XML_FEATURE_MAX_ENTITY_EXPANSIONS,
+                                      &max_expansions)) {
+            return PyErr_SetFromErrno(PyExc_ValueError);
+        }
     }
     else {
         max_expansions = PyLong_AsLong(expansions);
     }
 
     if (ignore_dtd == NULL) {
-        EXPAT(GetFeatureDefault)(XML_FEATURE_RESET_DTD,
-                                 &ignore_dtd_flag);
+        if (!EXPAT(GetFeatureDefault)(XML_FEATURE_RESET_DTD,
+                                      &ignore_dtd_flag)) {
+            return PyErr_SetFromErrno(PyExc_ValueError);
+        }
     }
     else if ((ignore_dtd_flag = PyObject_IsTrue(ignore_dtd)) == -1) {
              return NULL;
     }
 
 #ifdef XML_BOMB_PROTECTION
-    EXPAT(SetFeature)(self->parser, XML_FEATURE_MAX_ENTITY_INDIRECTIONS,
-                      max_indirections);
-    EXPAT(SetFeature)(self->parser, XML_FEATURE_MAX_ENTITY_EXPANSIONS,
-                      max_expansions);
-    EXPAT(SetFeature)(self->parser, XML_FEATURE_RESET_DTD,
-                      ignore_dtd_flag);
+    if (!EXPAT(SetFeature)(self->parser,
+                           XML_FEATURE_MAX_ENTITY_INDIRECTIONS,
+                           max_indirections)) {
+        return PyErr_SetFromErrno(PyExc_ValueError);
+    }
+    if (!EXPAT(SetFeature)(self->parser,
+                           XML_FEATURE_MAX_ENTITY_EXPANSIONS,
+                           max_expansions)) {
+        return PyErr_SetFromErrno(PyExc_ValueError);
+    }
+    if (!EXPAT(SetFeature)(self->parser,
+                           XML_FEATURE_RESET_DTD,
+                           ignore_dtd_flag)) {
+        return PyErr_SetFromErrno(PyExc_ValueError);
+    }
 #endif
 
     /* setup target handlers */

File Modules27/pyexpat.c

     if (name[0] == 'm') {
         if (strcmp(name, "max_entity_indirections") == 0) {
             long value = -1;
-            XML_GetFeature(self->itself, XML_FEATURE_MAX_ENTITY_INDIRECTIONS,
-                           &value);
+            if (!XML_GetFeature(self->itself,
+                                XML_FEATURE_MAX_ENTITY_INDIRECTIONS,
+                                &value)) {
+                return PyErr_SetFromErrno(PyExc_ValueError);
+            }
             return PyInt_FromLong(value);
         }
         if (strcmp(name, "max_entity_expansions") == 0) {
             long value = -1;
-            XML_GetFeature(self->itself, XML_FEATURE_MAX_ENTITY_EXPANSIONS,
-                           &value);
+            if (!XML_GetFeature(self->itself,
+                                XML_FEATURE_MAX_ENTITY_EXPANSIONS,
+                                &value)) {
+                return PyErr_SetFromErrno(PyExc_ValueError);
+            }
             return PyInt_FromLong(value);
         }
     }
 #ifdef XML_BOMB_PROTECTION
     if (strcmp(name, "reset_dtd") == 0) {
         long value = -1;
-        XML_GetFeature(self->itself, XML_FEATURE_RESET_DTD, &value);
+        if (!XML_GetFeature(self->itself, XML_FEATURE_RESET_DTD, &value)) {
+            return PyErr_SetFromErrno(PyExc_ValueError);
+        }
         return PyBool_FromLong(value);
     }
 #endif
                          UINT_MAX);
             return -1;
         }
-        XML_SetFeature(self->itself, XML_FEATURE_MAX_ENTITY_EXPANSIONS,
-                       value);
+        if (!XML_SetFeature(self->itself,
+                            XML_FEATURE_MAX_ENTITY_EXPANSIONS,
+                            value)) {
+            PyErr_SetFromErrno(PyExc_ValueError);
+            return -1;
+        }
         return 0;
     }
 
                          UINT_MAX);
             return -1;
         }
-        XML_SetFeature(self->itself, XML_FEATURE_MAX_ENTITY_INDIRECTIONS,
-                       value);
+        if (!XML_SetFeature(self->itself,
+                            XML_FEATURE_MAX_ENTITY_INDIRECTIONS,
+                            value)) {
+            PyErr_SetFromErrno(PyExc_ValueError);
+            return -1;
+        }
         return 0;
     }
 
         if ((value = PyObject_IsTrue(v)) == -1) {
             return -1;
         }
-        XML_SetFeature(self->itself, XML_FEATURE_RESET_DTD,
-                       value ? XML_TRUE : XML_FALSE);
+        if (!XML_SetFeature(self->itself, XML_FEATURE_RESET_DTD,
+                            value ? XML_TRUE : XML_FALSE)) {
+            PyErr_SetFromErrno(PyExc_ValueError);
+            return -1;
+        }
         return 0;
     }
 #endif

File Modules31/_elementtree.c

 
 #ifdef XML_BOMB_PROTECTION
     if (indirections == NULL || indirections == Py_None) {
-        EXPAT(GetFeatureDefault)(XML_FEATURE_MAX_ENTITY_INDIRECTIONS,
-                                 &max_indirections);
+        if (!EXPAT(GetFeatureDefault)(XML_FEATURE_MAX_ENTITY_INDIRECTIONS,
+                                      &max_indirections)) {
+            return PyErr_SetFromErrno(PyExc_ValueError);
+        }
     }
     else {
         max_indirections = PyLong_AsLong(indirections);
     }
 
     if (expansions == NULL || expansions == Py_None) {
-        EXPAT(GetFeatureDefault)(XML_FEATURE_MAX_ENTITY_EXPANSIONS,
-                                 &max_expansions);
+        if (!EXPAT(GetFeatureDefault)(XML_FEATURE_MAX_ENTITY_EXPANSIONS,
+                                      &max_expansions)) {
+            return PyErr_SetFromErrno(PyExc_ValueError);
+        }
     }
     else {
         max_expansions = PyLong_AsLong(expansions);
     }
 
     if (ignore_dtd == NULL) {
-        EXPAT(GetFeatureDefault)(XML_FEATURE_RESET_DTD,
-                                 &ignore_dtd_flag);
+        if (!EXPAT(GetFeatureDefault)(XML_FEATURE_RESET_DTD,
+                                      &ignore_dtd_flag)) {
+            return PyErr_SetFromErrno(PyExc_ValueError);
+        }
     }
     else if ((ignore_dtd_flag = PyObject_IsTrue(ignore_dtd)) == -1) {
              return NULL;
     }
 
 #ifdef XML_BOMB_PROTECTION
-    EXPAT(SetFeature)(self->parser, XML_FEATURE_MAX_ENTITY_INDIRECTIONS,
-                      max_indirections);
-    EXPAT(SetFeature)(self->parser, XML_FEATURE_MAX_ENTITY_EXPANSIONS,
-                      max_expansions);
-    EXPAT(SetFeature)(self->parser, XML_FEATURE_RESET_DTD,
-                      ignore_dtd_flag);
+    if (!EXPAT(SetFeature)(self->parser,
+                           XML_FEATURE_MAX_ENTITY_INDIRECTIONS,
+                           max_indirections)) {
+        return PyErr_SetFromErrno(PyExc_ValueError);
+    }
+    if (!EXPAT(SetFeature)(self->parser,
+                           XML_FEATURE_MAX_ENTITY_EXPANSIONS,
+                           max_expansions)) {
+        return PyErr_SetFromErrno(PyExc_ValueError);
+    }
+    if (!EXPAT(SetFeature)(self->parser,
+                           XML_FEATURE_RESET_DTD,
+                           ignore_dtd_flag)) {
+        return PyErr_SetFromErrno(PyExc_ValueError);
+    }
 #endif
 
     /* setup target handlers */

File Modules31/pyexpat.c

     if (name[0] == 'm') {
         if (strcmp(name, "max_entity_indirections") == 0) {
             long value = -1;
-            XML_GetFeature(self->itself, XML_FEATURE_MAX_ENTITY_INDIRECTIONS,
-                           &value);
+            if (!XML_GetFeature(self->itself,
+                                XML_FEATURE_MAX_ENTITY_INDIRECTIONS,
+                                &value)) {
+                return PyErr_SetFromErrno(PyExc_ValueError);
+            }
             return PyLong_FromLong(value);
         }
         if (strcmp(name, "max_entity_expansions") == 0){
             long value = -1;
-            XML_GetFeature(self->itself, XML_FEATURE_MAX_ENTITY_EXPANSIONS,
-                           &value);
-            return PyLong_FromLong(value);
+            if (!XML_GetFeature(self->itself,
+                                XML_FEATURE_MAX_ENTITY_EXPANSIONS,
+                                &value)) {
+                return PyErr_SetFromErrno(PyExc_ValueError);
+            }            return PyLong_FromLong(value);
         }
     }
 #endif
 #ifdef XML_BOMB_PROTECTION
     if (strcmp(name, "reset_dtd") == 0) {
         long value = -1;
-        XML_GetFeature(self->itself, XML_FEATURE_RESET_DTD, &value);
+        if (!XML_GetFeature(self->itself, XML_FEATURE_RESET_DTD, &value)) {
+            return PyErr_SetFromErrno(PyExc_ValueError);
+        }
         return PyBool_FromLong(value);
     }
 #endif
                          UINT_MAX);
             return -1;
         }
-        XML_SetFeature(self->itself, XML_FEATURE_MAX_ENTITY_EXPANSIONS,
-                       value);
+        if (!XML_SetFeature(self->itself,
+                            XML_FEATURE_MAX_ENTITY_EXPANSIONS,
+                            value)) {
+            PyErr_SetFromErrno(PyExc_ValueError);
+            return -1;
+        }
         return 0;
     }
 
                          UINT_MAX);
             return -1;
         }
-        XML_SetFeature(self->itself, XML_FEATURE_MAX_ENTITY_INDIRECTIONS,
-                       value);
+        if (!XML_SetFeature(self->itself,
+                            XML_FEATURE_MAX_ENTITY_INDIRECTIONS,
+                            value)) {
+            PyErr_SetFromErrno(PyExc_ValueError);
+            return -1;
+        }
         return 0;
     }
 
         if ((value = PyObject_IsTrue(v)) == -1) {
             return -1;
         }
-        XML_SetFeature(self->itself, XML_FEATURE_RESET_DTD,
-                       value ? XML_TRUE : XML_FALSE);
+        if (!XML_SetFeature(self->itself, XML_FEATURE_RESET_DTD,
+                            value ? XML_TRUE : XML_FALSE)) {
+            PyErr_SetFromErrno(PyExc_ValueError);
+            return -1;
+        }
         return 0;
     }
 #endif

File Modules32/_elementtree.c

 
 #ifdef XML_BOMB_PROTECTION
     if (indirections == NULL || indirections == Py_None) {
-        EXPAT(GetFeatureDefault)(XML_FEATURE_MAX_ENTITY_INDIRECTIONS,
-                                 &max_indirections);
+        if (!EXPAT(GetFeatureDefault)(XML_FEATURE_MAX_ENTITY_INDIRECTIONS,
+                                      &max_indirections)) {
+            return PyErr_SetFromErrno(PyExc_ValueError);
+        }
     }
     else {
         max_indirections = PyLong_AsLong(indirections);
     }
 
     if (expansions == NULL || expansions == Py_None) {
-        EXPAT(GetFeatureDefault)(XML_FEATURE_MAX_ENTITY_EXPANSIONS,
-                                 &max_expansions);
+        if (!EXPAT(GetFeatureDefault)(XML_FEATURE_MAX_ENTITY_EXPANSIONS,
+                                      &max_expansions)) {
+            return PyErr_SetFromErrno(PyExc_ValueError);
+        }
     }
     else {
         max_expansions = PyLong_AsLong(expansions);
     }
 
     if (ignore_dtd == NULL) {
-        EXPAT(GetFeatureDefault)(XML_FEATURE_RESET_DTD,
-                                 &ignore_dtd_flag);
+        if (!EXPAT(GetFeatureDefault)(XML_FEATURE_RESET_DTD,
+                                      &ignore_dtd_flag)) {
+            return PyErr_SetFromErrno(PyExc_ValueError);
+        }
     }
     else if ((ignore_dtd_flag = PyObject_IsTrue(ignore_dtd)) == -1) {
              return NULL;
     }
 
 #ifdef XML_BOMB_PROTECTION
-    EXPAT(SetFeature)(self->parser, XML_FEATURE_MAX_ENTITY_INDIRECTIONS,
-                      max_indirections);
-    EXPAT(SetFeature)(self->parser, XML_FEATURE_MAX_ENTITY_EXPANSIONS,
-                      max_expansions);
-    EXPAT(SetFeature)(self->parser, XML_FEATURE_RESET_DTD,
-                      ignore_dtd_flag);
+    if (!EXPAT(SetFeature)(self->parser,
+                           XML_FEATURE_MAX_ENTITY_INDIRECTIONS,
+                           max_indirections)) {
+        return PyErr_SetFromErrno(PyExc_ValueError);
+    }
+    if (!EXPAT(SetFeature)(self->parser,
+                           XML_FEATURE_MAX_ENTITY_EXPANSIONS,
+                           max_expansions)) {
+        return PyErr_SetFromErrno(PyExc_ValueError);
+    }
+    if (!EXPAT(SetFeature)(self->parser,
+                           XML_FEATURE_RESET_DTD,
+                           ignore_dtd_flag)) {
+        return PyErr_SetFromErrno(PyExc_ValueError);
+    }
 #endif
 
     /* setup target handlers */

File Modules32/pyexpat.c

     if (name[0] == 'm') {
         if (PyUnicode_CompareWithASCIIString(nameobj, "max_entity_indirections") == 0) {
             long value = -1;
-            XML_GetFeature(self->itself, XML_FEATURE_MAX_ENTITY_INDIRECTIONS,
-                           &value);
+            if (!XML_GetFeature(self->itself,
+                                XML_FEATURE_MAX_ENTITY_INDIRECTIONS,
+                                &value)) {
+                return PyErr_SetFromErrno(PyExc_ValueError);
+            }
             return PyLong_FromLong(value);
         }
         if (PyUnicode_CompareWithASCIIString(nameobj, "max_entity_expansions") == 0) {
             long value = -1;
-            XML_GetFeature(self->itself, XML_FEATURE_MAX_ENTITY_EXPANSIONS,
-                           &value);
+            if (!XML_GetFeature(self->itself,
+                                XML_FEATURE_MAX_ENTITY_EXPANSIONS,
+                                &value)) {
+                return PyErr_SetFromErrno(PyExc_ValueError);
+            }
             return PyLong_FromLong(value);
         }
     }
 #ifdef XML_BOMB_PROTECTION
     if (PyUnicode_CompareWithASCIIString(nameobj, "reset_dtd") == 0) {
         long value = -1;
-        XML_GetFeature(self->itself, XML_FEATURE_RESET_DTD, &value);
+        if (!XML_GetFeature(self->itself, XML_FEATURE_RESET_DTD, &value)) {
+            return PyErr_SetFromErrno(PyExc_ValueError);
+        }
         return PyBool_FromLong(value);
     }
 #endif
                          UINT_MAX);
             return -1;
         }
-        XML_SetFeature(self->itself, XML_FEATURE_MAX_ENTITY_EXPANSIONS,
-                       value);
+        if (!XML_SetFeature(self->itself,
+                            XML_FEATURE_MAX_ENTITY_EXPANSIONS,
+                            value)) {
+            PyErr_SetFromErrno(PyExc_ValueError);
+            return -1;
+        }
         return 0;
     }
 
                          UINT_MAX);
             return -1;
         }
-        XML_SetFeature(self->itself, XML_FEATURE_MAX_ENTITY_INDIRECTIONS,
-                       value);
+        if (!XML_SetFeature(self->itself,
+                            XML_FEATURE_MAX_ENTITY_INDIRECTIONS,
+                            value)) {
+            PyErr_SetFromErrno(PyExc_ValueError);
+            return -1;
+        }
         return 0;
     }
 
         if ((value = PyObject_IsTrue(v)) == -1) {
             return -1;
         }
-        XML_SetFeature(self->itself, XML_FEATURE_RESET_DTD,
-                       value ? XML_TRUE : XML_FALSE);
+        if (!XML_SetFeature(self->itself, XML_FEATURE_RESET_DTD,
+                            value ? XML_TRUE : XML_FALSE)) {
+            PyErr_SetFromErrno(PyExc_ValueError);
+            return -1;
+        }
         return 0;
     }
 #endif

File Modules33/_elementtree.c

 
 #ifdef XML_BOMB_PROTECTION
     if (indirections == NULL || indirections == Py_None) {
-        EXPAT(GetFeatureDefault)(XML_FEATURE_MAX_ENTITY_INDIRECTIONS,
-                                 &max_indirections);
+        if (!EXPAT(GetFeatureDefault)(XML_FEATURE_MAX_ENTITY_INDIRECTIONS,
+                                      &max_indirections)) {
+            PyErr_SetFromErrno(PyExc_ValueError);
+            return -1;
+        }
     }
     else {
         max_indirections = PyLong_AsLong(indirections);
     }
 
     if (expansions == NULL || expansions == Py_None) {
-        EXPAT(GetFeatureDefault)(XML_FEATURE_MAX_ENTITY_EXPANSIONS,
-                                 &max_expansions);
+        if (!EXPAT(GetFeatureDefault)(XML_FEATURE_MAX_ENTITY_EXPANSIONS,
+                                      &max_expansions)) {
+            PyErr_SetFromErrno(PyExc_ValueError);
+            return -1;
+        }
     }
     else {
         max_expansions = PyLong_AsLong(expansions);
     }
 
     if (ignore_dtd == NULL) {
-        EXPAT(GetFeatureDefault)(XML_FEATURE_RESET_DTD,
-                                 &ignore_dtd_flag);
+        if (!EXPAT(GetFeatureDefault)(XML_FEATURE_RESET_DTD,
+                                      &ignore_dtd_flag)) {
+            PyErr_SetFromErrno(PyExc_ValueError);
+            return -1;
+        }
     }
     else if ((ignore_dtd_flag = PyObject_IsTrue(ignore_dtd)) == -1) {
              return -1;
     }
 
 #ifdef XML_BOMB_PROTECTION
-    EXPAT(SetFeature)(self_xp->parser, XML_FEATURE_MAX_ENTITY_INDIRECTIONS,
-                      max_indirections);
-    EXPAT(SetFeature)(self_xp->parser, XML_FEATURE_MAX_ENTITY_EXPANSIONS,
-                      max_expansions);
-    EXPAT(SetFeature)(self_xp->parser, XML_FEATURE_RESET_DTD,
-                      ignore_dtd_flag);
+    if (!EXPAT(SetFeature)(self_xp->parser,
+                           XML_FEATURE_MAX_ENTITY_INDIRECTIONS,
+                           max_indirections)) {
+        PyErr_SetFromErrno(PyExc_ValueError);
+        return -1;
+    }
+    if (!EXPAT(SetFeature)(self_xp->parser,
+                           XML_FEATURE_MAX_ENTITY_EXPANSIONS,
+                           max_expansions)) {
+        PyErr_SetFromErrno(PyExc_ValueError);
+        return -1;
+    }
+    if (!EXPAT(SetFeature)(self_xp->parser,
+                           XML_FEATURE_RESET_DTD,
+                           ignore_dtd_flag)) {
+        PyErr_SetFromErrno(PyExc_ValueError);
+        return -1;
+    }
 #endif
 
     if (target) {

File Modules33/pyexpat.c

     if (first_char == 'm') {
         if (PyUnicode_CompareWithASCIIString(nameobj, "max_entity_indirections") == 0) {
             long value = -1;
-            XML_GetFeature(self->itself, XML_FEATURE_MAX_ENTITY_INDIRECTIONS,
-                           &value);
+            if (!XML_GetFeature(self->itself,
+                                XML_FEATURE_MAX_ENTITY_INDIRECTIONS,
+                                &value)) {
+                return PyErr_SetFromErrno(PyExc_ValueError);
+            }
             return PyLong_FromLong(value);
         }
         if (PyUnicode_CompareWithASCIIString(nameobj, "max_entity_expansions") == 0) {
             long value = -1;
-            XML_GetFeature(self->itself, XML_FEATURE_MAX_ENTITY_EXPANSIONS,
-                           &value);
-            return PyLong_FromLong(value);        }
+            if (!XML_GetFeature(self->itself,
+                                XML_FEATURE_MAX_ENTITY_EXPANSIONS,
+                                &value)) {
+                return PyErr_SetFromErrno(PyExc_ValueError);
+            }
+            return PyLong_FromLong(value);
+        }
     }
 #endif
     if (PyUnicode_CompareWithASCIIString(nameobj, "namespace_prefixes") == 0)
 #ifdef XML_BOMB_PROTECTION
     if (PyUnicode_CompareWithASCIIString(nameobj, "reset_dtd") == 0) {
         long value = -1;
-        XML_GetFeature(self->itself, XML_FEATURE_RESET_DTD, &value);
+        if (!XML_GetFeature(self->itself, XML_FEATURE_RESET_DTD, &value)) {
+            return PyErr_SetFromErrno(PyExc_ValueError);
+        }
         return PyBool_FromLong(value);
     }
 #endif
                          UINT_MAX);
             return -1;
         }
-        XML_SetFeature(self->itself, XML_FEATURE_MAX_ENTITY_EXPANSIONS,
-                       value);
+        if (!XML_SetFeature(self->itself,
+                            XML_FEATURE_MAX_ENTITY_EXPANSIONS,
+                            value)) {
+            PyErr_SetFromErrno(PyExc_ValueError);
+            return -1;
+        }
         return 0;
     }
 
                          UINT_MAX);
             return -1;
         }
-        XML_SetFeature(self->itself, XML_FEATURE_MAX_ENTITY_INDIRECTIONS,
-                       value);
+        if (!XML_SetFeature(self->itself,
+                            XML_FEATURE_MAX_ENTITY_INDIRECTIONS,
+                            value)) {
+            PyErr_SetFromErrno(PyExc_ValueError);
+            return -1;
+        }
         return 0;
     }
 
         if ((value = PyObject_IsTrue(v)) == -1) {
             return -1;
         }
-        XML_SetFeature(self->itself, XML_FEATURE_RESET_DTD,
-                       value ? XML_TRUE : XML_FALSE);
+        if (!XML_SetFeature(self->itself, XML_FEATURE_RESET_DTD,
+                            value ? XML_TRUE : XML_FALSE)) {
+            PyErr_SetFromErrno(PyExc_ValueError);
+            return -1;
+        }
         return 0;
     }
 #endif