gentleknife / rpms / expat

Forked from rpms/expat 4 years ago
Clone

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

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