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

589ceb
commit 3a4141add108097fa548b196f5950c6663e1578e
589ceb
Author: Tomas Korbar <tkorbar@redhat.com>
589ceb
Date:   Thu Mar 3 13:50:20 2022 +0100
589ceb
589ceb
    CVE-2022-25315
589ceb
589ceb
diff --git a/lib/xmlparse.c b/lib/xmlparse.c
589ceb
index f0061c8..45fda00 100644
589ceb
--- a/lib/xmlparse.c
589ceb
+++ b/lib/xmlparse.c
589ceb
@@ -2508,6 +2508,7 @@ storeRawNames(XML_Parser parser)
589ceb
   while (tag) {
589ceb
     int bufSize;
589ceb
     int nameLen = sizeof(XML_Char) * (tag->name.strLen + 1);
589ceb
+    size_t rawNameLen;
589ceb
     char *rawNameBuf = tag->buf + nameLen;
589ceb
     /* Stop if already stored.  Since m_tagStack is a stack, we can stop
589ceb
        at the first entry that has already been copied; everything
589ceb
@@ -2519,7 +2520,11 @@ storeRawNames(XML_Parser parser)
589ceb
     /* For re-use purposes we need to ensure that the
589ceb
        size of tag->buf is a multiple of sizeof(XML_Char).
589ceb
     */
589ceb
-    bufSize = nameLen + ROUND_UP(tag->rawNameLength, sizeof(XML_Char));
589ceb
+    rawNameLen = ROUND_UP(tag->rawNameLength, sizeof(XML_Char));
589ceb
+    /* Detect and prevent integer overflow. */
589ceb
+    if (rawNameLen > (size_t)INT_MAX - nameLen)
589ceb
+      return XML_FALSE;
589ceb
+    bufSize = nameLen + (int)rawNameLen;
589ceb
     if (bufSize > tag->bufEnd - tag->buf) {
589ceb
       char *temp = (char *)REALLOC(parser, tag->buf, bufSize);
589ceb
       if (temp == NULL)