|
|
463a2a |
From ede41d1e186ed2aba88a06e84cac839b770af3a1 Mon Sep 17 00:00:00 2001
|
|
|
463a2a |
From: Sebastian Pipping <sebastian@pipping.org>
|
|
|
463a2a |
Date: Wed, 26 Jan 2022 02:36:43 +0100
|
|
|
463a2a |
Subject: [PATCH 1/2] lib: Prevent integer overflow in doProlog
|
|
|
463a2a |
(CVE-2022-23990)
|
|
|
463a2a |
|
|
|
463a2a |
The change from "int nameLen" to "size_t nameLen"
|
|
|
463a2a |
addresses the overflow on "nameLen++" in code
|
|
|
463a2a |
"for (; name[nameLen++];)" right above the second
|
|
|
463a2a |
change in the patch.
|
|
|
463a2a |
---
|
|
|
463a2a |
expat/lib/xmlparse.c | 10 ++++++++--
|
|
|
463a2a |
1 file changed, 8 insertions(+), 2 deletions(-)
|
|
|
463a2a |
|
|
|
463a2a |
diff --git a/lib/xmlparse.c b/lib/xmlparse.c
|
|
|
463a2a |
index 5ce31402..d1d17005 100644
|
|
|
463a2a |
--- a/lib/xmlparse.c
|
|
|
463a2a |
+++ b/lib/xmlparse.c
|
|
|
463a2a |
@@ -5372,7 +5372,7 @@ doProlog(XML_Parser parser, const ENCODING *enc, const char *s, const char *end,
|
|
|
463a2a |
if (dtd->in_eldecl) {
|
|
|
463a2a |
ELEMENT_TYPE *el;
|
|
|
463a2a |
const XML_Char *name;
|
|
|
463a2a |
- int nameLen;
|
|
|
463a2a |
+ size_t nameLen;
|
|
|
463a2a |
const char *nxt
|
|
|
463a2a |
= (quant == XML_CQUANT_NONE ? next : next - enc->minBytesPerChar);
|
|
|
463a2a |
int myindex = nextScaffoldPart(parser);
|
|
|
463a2a |
@@ -5388,7 +5388,13 @@ doProlog(XML_Parser parser, const ENCODING *enc, const char *s, const char *end,
|
|
|
463a2a |
nameLen = 0;
|
|
|
463a2a |
for (; name[nameLen++];)
|
|
|
463a2a |
;
|
|
|
463a2a |
- dtd->contentStringLen += nameLen;
|
|
|
463a2a |
+
|
|
|
463a2a |
+ /* Detect and prevent integer overflow */
|
|
|
463a2a |
+ if (nameLen > UINT_MAX - dtd->contentStringLen) {
|
|
|
463a2a |
+ return XML_ERROR_NO_MEMORY;
|
|
|
463a2a |
+ }
|
|
|
463a2a |
+
|
|
|
463a2a |
+ dtd->contentStringLen += (unsigned)nameLen;
|
|
|
463a2a |
if (parser->m_elementDeclHandler)
|
|
|
463a2a |
handleDefault = XML_FALSE;
|
|
|
463a2a |
}
|