Blame SOURCES/expat-2.1.0-Prevent-integer-overflow-in-storeRawNames.patch

4cc7ea
commit 1b57efe37fd4ef80058b05415a2a0e6b8eaab565
4cc7ea
Author: Tomas Korbar <tkorbar@redhat.com>
4cc7ea
Date:   Mon Mar 21 12:51:17 2022 +0100
4cc7ea
4cc7ea
    Prevent integer overflow in storeRawNames
4cc7ea
4cc7ea
diff --git a/lib/xmlparse.c b/lib/xmlparse.c
4cc7ea
index 4bfb860..989ab8c 100644
4cc7ea
--- a/lib/xmlparse.c
4cc7ea
+++ b/lib/xmlparse.c
4cc7ea
@@ -2099,6 +2099,7 @@ storeRawNames(XML_Parser parser)
4cc7ea
   while (tag) {
4cc7ea
     int bufSize;
4cc7ea
     int nameLen = sizeof(XML_Char) * (tag->name.strLen + 1);
4cc7ea
+    size_t rawNameLen;
4cc7ea
     char *rawNameBuf = tag->buf + nameLen;
4cc7ea
     /* Stop if already stored.  Since tagStack is a stack, we can stop
4cc7ea
        at the first entry that has already been copied; everything
4cc7ea
@@ -2110,7 +2111,11 @@ storeRawNames(XML_Parser parser)
4cc7ea
     /* For re-use purposes we need to ensure that the
4cc7ea
        size of tag->buf is a multiple of sizeof(XML_Char).
4cc7ea
     */
4cc7ea
-    bufSize = nameLen + ROUND_UP(tag->rawNameLength, sizeof(XML_Char));
4cc7ea
+    rawNameLen = ROUND_UP(tag->rawNameLength, sizeof(XML_Char));
4cc7ea
+    /* Detect and prevent integer overflow. */
4cc7ea
+    if (rawNameLen > (size_t)INT_MAX - nameLen)
4cc7ea
+      return XML_FALSE;
4cc7ea
+    bufSize = nameLen + (int)rawNameLen;
4cc7ea
     if (bufSize > tag->bufEnd - tag->buf) {
4cc7ea
       char *temp = (char *)REALLOC(tag->buf, bufSize);
4cc7ea
       if (temp == NULL)