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

463a2a
From 85ae9a2d7d0e9358f356b33977b842df8ebaec2b Mon Sep 17 00:00:00 2001
463a2a
From: Sebastian Pipping <sebastian@pipping.org>
463a2a
Date: Sat, 25 Dec 2021 20:52:08 +0100
463a2a
Subject: [PATCH] lib: Prevent integer overflow on m_groupSize in function
463a2a
 doProlog (CVE-2021-46143)
463a2a
463a2a
---
463a2a
 expat/lib/xmlparse.c | 15 +++++++++++++++
463a2a
 1 file changed, 15 insertions(+)
463a2a
463a2a
diff --git a/lib/xmlparse.c b/lib/xmlparse.c
463a2a
index b47c31b0..8f243126 100644
463a2a
--- a/lib/xmlparse.c
463a2a
+++ b/lib/xmlparse.c
463a2a
@@ -5046,6 +5046,11 @@ doProlog(XML_Parser parser, const ENCODING *enc, const char *s, const char *end,
463a2a
       if (parser->m_prologState.level >= parser->m_groupSize) {
463a2a
         if (parser->m_groupSize) {
463a2a
           {
463a2a
+            /* Detect and prevent integer overflow */
463a2a
+            if (parser->m_groupSize > (unsigned int)(-1) / 2u) {
463a2a
+              return XML_ERROR_NO_MEMORY;
463a2a
+            }
463a2a
+
463a2a
             char *const new_connector = (char *)REALLOC(
463a2a
                 parser, parser->m_groupConnector, parser->m_groupSize *= 2);
463a2a
             if (new_connector == NULL) {
463a2a
@@ -5056,6 +5061,16 @@ doProlog(XML_Parser parser, const ENCODING *enc, const char *s, const char *end,
463a2a
           }
463a2a
 
463a2a
           if (dtd->scaffIndex) {
463a2a
+            /* Detect and prevent integer overflow.
463a2a
+             * The preprocessor guard addresses the "always false" warning
463a2a
+             * from -Wtype-limits on platforms where
463a2a
+             * sizeof(unsigned int) < sizeof(size_t), e.g. on x86_64. */
463a2a
+#if UINT_MAX >= SIZE_MAX
463a2a
+            if (parser->m_groupSize > (size_t)(-1) / sizeof(int)) {
463a2a
+              return XML_ERROR_NO_MEMORY;
463a2a
+            }
463a2a
+#endif
463a2a
+
463a2a
             int *const new_scaff_index = (int *)REALLOC(
463a2a
                 parser, dtd->scaffIndex, parser->m_groupSize * sizeof(int));
463a2a
             if (new_scaff_index == NULL)