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

fa9cc6
commit 835df27bc1a1eae1ec51b14122ea40c974dd7409
fa9cc6
Author: Tomas Korbar <tkorbar@redhat.com>
fa9cc6
Date:   Mon Feb 14 12:29:20 2022 +0100
fa9cc6
fa9cc6
    CVE-2021-46143
fa9cc6
fa9cc6
diff --git a/lib/xmlparse.c b/lib/xmlparse.c
fa9cc6
index c45be0c..22d0a75 100644
fa9cc6
--- a/lib/xmlparse.c
fa9cc6
+++ b/lib/xmlparse.c
fa9cc6
@@ -4995,6 +4995,11 @@ doProlog(XML_Parser parser, const ENCODING *enc, const char *s, const char *end,
fa9cc6
     case XML_ROLE_GROUP_OPEN:
fa9cc6
       if (parser->m_prologState.level >= parser->m_groupSize) {
fa9cc6
         if (parser->m_groupSize) {
fa9cc6
+          /* Detect and prevent integer overflow */
fa9cc6
+          if (parser->m_groupSize > (unsigned int)(-1) / 2u) {
fa9cc6
+            return XML_ERROR_NO_MEMORY;
fa9cc6
+          }
fa9cc6
+
fa9cc6
           char *temp = (char *)REALLOC(parser, parser->m_groupConnector, parser->m_groupSize *= 2);
fa9cc6
           if (temp == NULL) {
fa9cc6
             parser->m_groupSize /= 2;
fa9cc6
@@ -5002,6 +5007,15 @@ doProlog(XML_Parser parser, const ENCODING *enc, const char *s, const char *end,
fa9cc6
           }
fa9cc6
           parser->m_groupConnector = temp;
fa9cc6
           if (dtd->scaffIndex) {
fa9cc6
+            /* Detect and prevent integer overflow.
fa9cc6
+             * The preprocessor guard addresses the "always false" warning
fa9cc6
+             * from -Wtype-limits on platforms where
fa9cc6
+             * sizeof(unsigned int) < sizeof(size_t), e.g. on x86_64. */
fa9cc6
+#if UINT_MAX >= SIZE_MAX
fa9cc6
+            if (parser->m_groupSize > (size_t)(-1) / sizeof(int)) {
fa9cc6
+              return XML_ERROR_NO_MEMORY;
fa9cc6
+            }
fa9cc6
+#endif
fa9cc6
             int *temp = (int *)REALLOC(parser, dtd->scaffIndex,
fa9cc6
                           parser->m_groupSize * sizeof(int));
fa9cc6
             if (temp == NULL)