Blame SOURCES/expat-2.1.0-CVE-2015-2716.patch

3032c4
3032c4
https://bugzilla.redhat.com/show_bug.cgi?id=CVE-2015-2716
3032c4
3032c4
Address CVE-2015-2716, which was also called CVE-2015-1283.
3032c4
3032c4
https://github.com/libexpat/libexpat/commit/ba0f9c3b40c264b8dd392e02a7a060a8fa54f032.patch
3032c4
https://github.com/libexpat/libexpat/commit/f0bec73b018caa07d3e75ec8dd967f3785d71bde.patch
3032c4
3032c4
--- expat-2.1.0/lib/xmlparse.c.cve2716
3032c4
+++ expat-2.1.0/lib/xmlparse.c
3032c4
@@ -1678,6 +1678,10 @@
3032c4
 void * XMLCALL
3032c4
 XML_GetBuffer(XML_Parser parser, int len)
3032c4
 {
3032c4
+  if (len < 0) {
3032c4
+    errorCode = XML_ERROR_NO_MEMORY;
3032c4
+    return NULL;
3032c4
+  }
3032c4
   switch (ps_parsing) {
3032c4
   case XML_SUSPENDED:
3032c4
     errorCode = XML_ERROR_SUSPENDED;
3032c4
@@ -1689,8 +1693,11 @@
3032c4
   }
3032c4
 
3032c4
   if (len > bufferLim - bufferEnd) {
3032c4
-    /* FIXME avoid integer overflow */
3032c4
-    int neededSize = len + (int)(bufferEnd - bufferPtr);
3032c4
+    int neededSize = (int) ((unsigned)len + (unsigned)(bufferEnd - bufferPtr));
3032c4
+    if (neededSize < 0) {
3032c4
+      errorCode = XML_ERROR_NO_MEMORY;
3032c4
+      return NULL;
3032c4
+    }
3032c4
 #ifdef XML_CONTEXT_BYTES
3032c4
     int keep = (int)(bufferPtr - buffer);
3032c4
 
3032c4
@@ -1718,8 +1725,13 @@
3032c4
       if (bufferSize == 0)
3032c4
         bufferSize = INIT_BUFFER_SIZE;
3032c4
       do {
3032c4
-        bufferSize *= 2;
3032c4
-      } while (bufferSize < neededSize);
3032c4
+        /* Do not invoke signed arithmetic overflow: */
3032c4
+        bufferSize = (int) (2U * (unsigned) bufferSize);
3032c4
+      } while (bufferSize < neededSize && bufferSize > 0);
3032c4
+      if (bufferSize <= 0) {
3032c4
+        errorCode = XML_ERROR_NO_MEMORY;
3032c4
+        return NULL;
3032c4
+      }
3032c4
       newBuf = (char *)MALLOC(bufferSize);
3032c4
       if (newBuf == 0) {
3032c4
         errorCode = XML_ERROR_NO_MEMORY;