Blame SOURCES/expat-2.1.0-Prevent-integer-overflow-on-m_groupSize-in-function.patch

4cc7ea
commit 9939d60f01ff598134628ea64b9b65d4b84209ce
4cc7ea
Author: Tomas Korbar <tkorbar@redhat.com>
4cc7ea
Date:   Mon Feb 21 17:09:17 2022 +0100
4cc7ea
4cc7ea
    CVE-2021-46143
4cc7ea
4cc7ea
diff --git a/lib/xmlparse.c b/lib/xmlparse.c
4cc7ea
index e743f78..1371f61 100644
4cc7ea
--- a/lib/xmlparse.c
4cc7ea
+++ b/lib/xmlparse.c
4cc7ea
@@ -4501,11 +4501,25 @@ doProlog(XML_Parser parser,
4cc7ea
     case XML_ROLE_GROUP_OPEN:
4cc7ea
       if (prologState.level >= groupSize) {
4cc7ea
         if (groupSize) {
4cc7ea
+          /* Detect and prevent integer overflow */
4cc7ea
+          if (parser->m_groupSize > (unsigned int)(-1) / 2u) {
4cc7ea
+            return XML_ERROR_NO_MEMORY;
4cc7ea
+          }
4cc7ea
+
4cc7ea
           char *temp = (char *)REALLOC(groupConnector, groupSize *= 2);
4cc7ea
           if (temp == NULL)
4cc7ea
             return XML_ERROR_NO_MEMORY;
4cc7ea
           groupConnector = temp;
4cc7ea
           if (dtd->scaffIndex) {
4cc7ea
+            /* Detect and prevent integer overflow.
4cc7ea
+             * The preprocessor guard addresses the "always false" warning
4cc7ea
+             * from -Wtype-limits on platforms where
4cc7ea
+             * sizeof(unsigned int) < sizeof(size_t), e.g. on x86_64. */
4cc7ea
+#if UINT_MAX >= SIZE_MAX
4cc7ea
+            if (parser->m_groupSize > (size_t)(-1) / sizeof(int)) {
4cc7ea
+              return XML_ERROR_NO_MEMORY;
4cc7ea
+            }
4cc7ea
+#endif
4cc7ea
             int *temp = (int *)REALLOC(dtd->scaffIndex,
4cc7ea
                           groupSize * sizeof(int));
4cc7ea
             if (temp == NULL)