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

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