CVE-2022-23990 expat: integer overflow in the doProlog function

Resolve: rhbz#2050503
This commit is contained in:
Tomas Korbar 2022-02-07 12:39:27 +01:00
parent 799d8d6c63
commit 020338314d
3 changed files with 49 additions and 15 deletions

View File

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

View File

@ -1,14 +0,0 @@
https://github.com/libexpat/libexpat/pull/109
--- libexpat-R_2_2_3/expat/tests/runtests.c.fixtests
+++ libexpat-R_2_2_3/expat/tests/runtests.c
@@ -5671,7 +5671,7 @@ static int XMLCALL
prefix_converter(void *UNUSED_P(data), const char *s)
{
/* If the first byte is 0xff, raise an error */
- if (s[0] == -1)
+ if (s[0] == (char)-1)
return -1;
/* Just add the low bits of the first byte to the second */
return (s[1] + (s[0] & 0x7f)) & 0x01ff;

View File

@ -3,12 +3,13 @@
Summary: An XML parser library
Name: expat
Version: %(echo %{unversion} | sed 's/_/./g')
Release: 4%{?dist}
Release: 5%{?dist}
Source: https://github.com/libexpat/libexpat/archive/R_%{unversion}.tar.gz#/expat-%{version}.tar.gz
URL: https://libexpat.github.io/
License: MIT
BuildRequires: autoconf, libtool, xmlto, gcc-c++
BuildRequires: make
Patch0: expat-2.2.10-prevent-integer-overflow-in-doProlog.patch
%description
This is expat, the C library for parsing XML, written by James Clark. Expat
@ -36,6 +37,7 @@ Install it if you need to link statically with expat.
%prep
%setup -q -n libexpat-R_%{unversion}/expat
%patch0 -p1 -b .CVE-2022-23990
sed -i 's/install-data-hook/do-nothing-please/' lib/Makefile.am
./buildconf.sh
@ -72,6 +74,10 @@ make check
%{_libdir}/lib*.a
%changelog
* Mon Feb 07 2022 Tomas Korbar <tkorbar@redhat.com> - 2.2.10-5
- CVE-2022-23990 expat: integer overflow in the doProlog function
- Resolve: rhbz#2050503
* Mon Aug 09 2021 Mohan Boddu <mboddu@redhat.com> - 2.2.10-4
- Rebuilt for IMA sigs, glibc 2.34, aarch64 flags
Related: rhbz#1991688