blob: 82243466607bff0a93e8a5e4c39d865924b81fae [file] [log] [blame]
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001From 50f06b3efb638efb0abd95dc62dca05ae67882c2 Mon Sep 17 00:00:00 2001
2From: Nick Wellnhofer <wellnhofer@aevum.de>
3Date: Fri, 7 Aug 2020 21:54:27 +0200
4Subject: [PATCH] Fix out-of-bounds read with 'xmllint --htmlout'
5
6Make sure that truncated UTF-8 sequences don't cause an out-of-bounds
7array access.
8
9Thanks to @SuhwanSong and the Agency for Defense Development (ADD) for
10the report.
11
12Fixes #178.
13
14CVE: CVE-2020-24977
15Upstream-Status: Backport [https://gitlab.gnome.org/GNOME/libxml2/-/commit/50f06b3efb638efb0abd95dc62dca05ae67882c2]
16
17Signed-off-by: Ovidiu Panait <ovidiu.panait@windriver.com>
18---
19 xmllint.c | 6 ++++++
20 1 file changed, 6 insertions(+)
21
22diff --git a/xmllint.c b/xmllint.c
23index f6a8e463..c647486f 100644
24--- a/xmllint.c
25+++ b/xmllint.c
26@@ -528,6 +528,12 @@ static void
27 xmlHTMLEncodeSend(void) {
28 char *result;
29
30+ /*
31+ * xmlEncodeEntitiesReentrant assumes valid UTF-8, but the buffer might
32+ * end with a truncated UTF-8 sequence. This is a hack to at least avoid
33+ * an out-of-bounds read.
34+ */
35+ memset(&buffer[sizeof(buffer)-4], 0, 4);
36 result = (char *) xmlEncodeEntitiesReentrant(NULL, BAD_CAST buffer);
37 if (result) {
38 xmlGenericError(xmlGenericErrorContext, "%s", result);
39--
402.17.1
41