commit:     cf3128be852f26ac32c5dd67e904012b094b9496
Author:     Benjamin Gordon <bmgordon <AT> chromium <DOT> org>
AuthorDate: Fri Mar  5 16:25:29 2021 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Thu Mar 11 17:47:44 2021 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=cf3128be

dev-libs/libxml2: Add upstream patch for xmllint

This fixes an out-of-bounds read in xmllint when built with icu.  See
CVE-2020-24977 and https://gitlab.gnome.org/GNOME/libxml2/-/issues/178
for more info.

Signed-off-by: Benjamin Gordon <bmgordon <AT> chromium.org>
Bug: https://bugs.gentoo.org/749849
Closes: https://github.com/gentoo/gentoo/pull/19835
Signed-off-by: Sam James <sam <AT> gentoo.org>

 .../files/libxml2-2.9.10-xmllint-utf8.patch        | 36 ++++++++++++++++++++++
 ...2-2.9.10-r4.ebuild => libxml2-2.9.10-r5.ebuild} |  3 ++
 2 files changed, 39 insertions(+)

diff --git a/dev-libs/libxml2/files/libxml2-2.9.10-xmllint-utf8.patch 
b/dev-libs/libxml2/files/libxml2-2.9.10-xmllint-utf8.patch
new file mode 100644
index 00000000000..7807b32cce5
--- /dev/null
+++ b/dev-libs/libxml2/files/libxml2-2.9.10-xmllint-utf8.patch
@@ -0,0 +1,36 @@
+From 50f06b3efb638efb0abd95dc62dca05ae67882c2 Mon Sep 17 00:00:00 2001
+From: Nick Wellnhofer <[email protected]>
+Date: Fri, 7 Aug 2020 21:54:27 +0200
+Subject: [PATCH] Fix out-of-bounds read with 'xmllint --htmlout'
+
+Make sure that truncated UTF-8 sequences don't cause an out-of-bounds
+array access.
+
+Thanks to @SuhwanSong and the Agency for Defense Development (ADD) for
+the report.
+
+Fixes #178.
+---
+ xmllint.c | 6 ++++++
+ 1 file changed, 6 insertions(+)
+
+diff --git a/xmllint.c b/xmllint.c
+index f6a8e463..c647486f 100644
+--- a/xmllint.c
++++ b/xmllint.c
+@@ -528,6 +528,12 @@ static void
+ xmlHTMLEncodeSend(void) {
+     char *result;
+ 
++    /*
++     * xmlEncodeEntitiesReentrant assumes valid UTF-8, but the buffer might
++     * end with a truncated UTF-8 sequence. This is a hack to at least avoid
++     * an out-of-bounds read.
++     */
++    memset(&buffer[sizeof(buffer)-4], 0, 4);
+     result = (char *) xmlEncodeEntitiesReentrant(NULL, BAD_CAST buffer);
+     if (result) {
+       xmlGenericError(xmlGenericErrorContext, "%s", result);
+-- 
+GitLab
+

diff --git a/dev-libs/libxml2/libxml2-2.9.10-r4.ebuild 
b/dev-libs/libxml2/libxml2-2.9.10-r5.ebuild
similarity index 98%
rename from dev-libs/libxml2/libxml2-2.9.10-r4.ebuild
rename to dev-libs/libxml2/libxml2-2.9.10-r5.ebuild
index 9db3902e430..1e48320e3fd 100644
--- a/dev-libs/libxml2/libxml2-2.9.10-r4.ebuild
+++ b/dev-libs/libxml2/libxml2-2.9.10-r5.ebuild
@@ -92,6 +92,9 @@ src_prepare() {
        # bug #745162
        eapply "${FILESDIR}"/${PN}-2.9.8-python3-unicode-errors.patch
 
+       # https://gitlab.gnome.org/GNOME/libxml2/-/issues/178
+       eapply "${FILESDIR}"/${PN}-2.9.10-xmllint-utf8.patch
+
        if [[ ${CHOST} == *-darwin* ]] ; then
                # Avoid final linking arguments for python modules
                sed -i -e '/PYTHON_LIBS/s/ldflags/libs/' configure.ac || die

Reply via email to