Blame SOURCES/0005-lib-Prevent-more-integer-overflows-CVE-2022-22822-to.patch

f57d65
From ce6eddc1a167dafaac17c7bad9fa6b013fada31b Mon Sep 17 00:00:00 2001
f57d65
From: Rob Crittenden <rcritten@redhat.com>
f57d65
Date: Fri, 25 Feb 2022 13:07:07 -0500
f57d65
Subject: [PATCH 5/6] lib: Prevent more integer overflows (CVE-2022-22822 to
f57d65
 CVE-2022-22827)
f57d65
f57d65
Backport fixes from https://github.com/libexpat/libexpat/pull/539
f57d65
f57d65
Resolves: #2058567, #2058576, #2058282, #2058589, #2058595, #2058602
f57d65
---
f57d65
 lib/expat/xmlparse/xmlparse.c | 40 +++++++++++++++++++++++++++++++++++
f57d65
 1 file changed, 40 insertions(+)
f57d65
f57d65
diff --git a/lib/expat/xmlparse/xmlparse.c b/lib/expat/xmlparse/xmlparse.c
f57d65
index 48adfb3..16ab82a 100644
f57d65
--- a/lib/expat/xmlparse/xmlparse.c
f57d65
+++ b/lib/expat/xmlparse/xmlparse.c
f57d65
@@ -19,6 +19,7 @@ See the file copying.txt for copying permission.
f57d65
 #include <assert.h>
f57d65
 #include <limits.h>                     /* UINT_MAX */
f57d65
 #include <time.h>                       /* time() */
f57d65
+#include <stdint.h>
f57d65
 
f57d65
 #include "xmlrpc_config.h"
f57d65
 #include "c_util.h"
f57d65
@@ -1076,6 +1077,9 @@ int addBinding(XML_Parser parser,
f57d65
     ;
f57d65
   if (namespaceSeparator)
f57d65
     len++;
f57d65
+  if (namespaceSeparator && (uri[len] == namespaceSeparator)) {
f57d65
+    return XML_ERROR_SYNTAX;
f57d65
+  }
f57d65
   if (freeBindingList) {
f57d65
     b = freeBindingList;
f57d65
     if (len > b->uriAlloc) {
f57d65
@@ -2116,10 +2120,32 @@ storeAtts(XML_Parser       const xmlParserP,
f57d65
   }
f57d65
   /* get the attributes from the tokenizer */
f57d65
   n = XmlGetAttributes(enc, attStr, attsSize, atts);
f57d65
+
f57d65
+
f57d65
+  /* Detect and prevent integer overflow */
f57d65
+  if (n > INT_MAX - nDefaultAtts) {
f57d65
+    return XML_ERROR_NO_MEMORY;
f57d65
+  }
f57d65
+
f57d65
   if (n + nDefaultAtts > attsSize) {
f57d65
     int oldAttsSize = attsSize;
f57d65
     ATTRIBUTE *temp;
f57d65
+    /* Detect and prevent integer overflow */
f57d65
+    if ((nDefaultAtts > INT_MAX - INIT_ATTS_SIZE)
f57d65
+        || (n > INT_MAX - (nDefaultAtts + INIT_ATTS_SIZE))) {
f57d65
+      return XML_ERROR_NO_MEMORY;
f57d65
+    }
f57d65
     attsSize = n + nDefaultAtts + INIT_ATTS_SIZE;
f57d65
+    /* Detect and prevent integer overflow.
f57d65
+     * The preprocessor guard addresses the "always false" warning
f57d65
+     * from -Wtype-limits on platforms where
f57d65
+     * sizeof(unsigned int) < sizeof(size_t), e.g. on x86_64. */
f57d65
+#if UINT_MAX >= SIZE_MAX
f57d65
+    if ((unsigned)parser->m_attsSize > (size_t)(-1) / sizeof(ATTRIBUTE)) {
f57d65
+      attsSize = oldAttsSize;
f57d65
+      return XML_ERROR_NO_MEMORY;
f57d65
+    }
f57d65
+#endif
f57d65
     temp = realloc((void *)atts, attsSize * sizeof(ATTRIBUTE));
f57d65
     if (!temp)
f57d65
       return XML_ERROR_NO_MEMORY;
f57d65
@@ -2297,6 +2323,20 @@ storeAtts(XML_Parser       const xmlParserP,
f57d65
   n = i + binding->uriLen;
f57d65
   if (n > binding->uriAlloc) {
f57d65
     TAG *p;
f57d65
+
f57d65
+    /* Detect and prevent integer overflow */
f57d65
+    if (n > INT_MAX - EXPAND_SPARE) {
f57d65
+      return XML_ERROR_NO_MEMORY;
f57d65
+    }
f57d65
+    /* Detect and prevent integer overflow.
f57d65
+     * The preprocessor guard addresses the "always false" warning
f57d65
+     * from -Wtype-limits on platforms where
f57d65
+     * sizeof(unsigned int) < sizeof(size_t), e.g. on x86_64. */
f57d65
+#if UINT_MAX >= SIZE_MAX
f57d65
+    if ((unsigned)(n + EXPAND_SPARE) > (size_t)(-1) / sizeof(XML_Char)) {
f57d65
+      return XML_ERROR_NO_MEMORY;
f57d65
+    }
f57d65
+#endif
f57d65
     XML_Char *uri = malloc((n + EXPAND_SPARE) * sizeof(XML_Char));
f57d65
     if (!uri)
f57d65
       return XML_ERROR_NO_MEMORY;
f57d65
-- 
f57d65
2.31.1
f57d65