Blame SOURCES/libxml2-2.9.7-CVE-2021-3517.patch

f74686
From bf22713507fe1fc3a2c4b525cf0a88c2dc87a3a2 Mon Sep 17 00:00:00 2001
f74686
From: Joel Hockey <joel.hockey@gmail.com>
f74686
Date: Sun, 16 Aug 2020 17:19:35 -0700
f74686
Subject: [PATCH] Validate UTF8 in xmlEncodeEntities
f74686
f74686
Code is currently assuming UTF-8 without validating. Truncated UTF-8
f74686
input can cause out-of-bounds array access.
f74686
f74686
Adds further checks to partial fix in 50f06b3e.
f74686
f74686
Fixes #178
f74686
---
f74686
 entities.c | 16 +++++++++++++++-
f74686
 1 file changed, 15 insertions(+), 1 deletion(-)
f74686
f74686
diff --git a/entities.c b/entities.c
f74686
index 37b99a56..1a8f86f0 100644
f74686
--- a/entities.c
f74686
+++ b/entities.c
f74686
@@ -704,11 +704,25 @@ xmlEncodeEntitiesInternal(xmlDocPtr doc, const xmlChar *input, int attr) {
f74686
 	    } else {
f74686
 		/*
f74686
 		 * We assume we have UTF-8 input.
f74686
+		 * It must match either:
f74686
+		 *   110xxxxx 10xxxxxx
f74686
+		 *   1110xxxx 10xxxxxx 10xxxxxx
f74686
+		 *   11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
f74686
+		 * That is:
f74686
+		 *   cur[0] is 11xxxxxx
f74686
+		 *   cur[1] is 10xxxxxx
f74686
+		 *   cur[2] is 10xxxxxx if cur[0] is 111xxxxx
f74686
+		 *   cur[3] is 10xxxxxx if cur[0] is 1111xxxx
f74686
+		 *   cur[0] is not 11111xxx
f74686
 		 */
f74686
 		char buf[11], *ptr;
f74686
 		int val = 0, l = 1;
f74686
 
f74686
-		if (*cur < 0xC0) {
f74686
+		if (((cur[0] & 0xC0) != 0xC0) ||
f74686
+		    ((cur[1] & 0xC0) != 0x80) ||
f74686
+		    (((cur[0] & 0xE0) == 0xE0) && ((cur[2] & 0xC0) != 0x80)) ||
f74686
+		    (((cur[0] & 0xF0) == 0xF0) && ((cur[3] & 0xC0) != 0x80)) ||
f74686
+		    (((cur[0] & 0xF8) == 0xF8))) {
f74686
 		    xmlEntitiesErr(XML_CHECK_NOT_UTF8,
f74686
 			    "xmlEncodeEntities: input not UTF-8");
f74686
 		    if (doc != NULL)
f74686
-- 
f74686
GitLab
f74686