Blame SOURCES/libxml2-2.9.7-CVE-2016-3709.patch

e5eacc
From c1ba6f54d32b707ca6d91cb3257ce9de82876b6f Mon Sep 17 00:00:00 2001
e5eacc
From: Nick Wellnhofer <wellnhofer@aevum.de>
e5eacc
Date: Sat, 15 Aug 2020 18:32:29 +0200
e5eacc
Subject: [PATCH] Revert "Do not URI escape in server side includes"
e5eacc
e5eacc
This reverts commit 960f0e275616cadc29671a218d7fb9b69eb35588.
e5eacc
e5eacc
This commit introduced
e5eacc
e5eacc
- an infinite loop, found by OSS-Fuzz, which could be easily fixed.
e5eacc
- an algorithm with quadratic runtime
e5eacc
- a security issue, see
e5eacc
  https://bugzilla.gnome.org/show_bug.cgi?id=769760
e5eacc
e5eacc
A better approach is to add an option not to escape URLs at all
e5eacc
which libxml2 should have possibly done in the first place.
e5eacc
---
e5eacc
 HTMLtree.c | 49 +++++++++++--------------------------------------
e5eacc
 1 file changed, 11 insertions(+), 38 deletions(-)
e5eacc
e5eacc
diff --git a/HTMLtree.c b/HTMLtree.c
e5eacc
index 8d236bb3..cdb7f86a 100644
e5eacc
--- a/HTMLtree.c
e5eacc
+++ b/HTMLtree.c
e5eacc
@@ -706,49 +706,22 @@ htmlAttrDumpOutput(xmlOutputBufferPtr buf, xmlDocPtr doc, xmlAttrPtr cur,
e5eacc
 		 (!xmlStrcasecmp(cur->name, BAD_CAST "src")) ||
e5eacc
 		 ((!xmlStrcasecmp(cur->name, BAD_CAST "name")) &&
e5eacc
 		  (!xmlStrcasecmp(cur->parent->name, BAD_CAST "a"))))) {
e5eacc
+		xmlChar *escaped;
e5eacc
 		xmlChar *tmp = value;
e5eacc
-		/* xmlURIEscapeStr() escapes '"' so it can be safely used. */
e5eacc
-		xmlBufCCat(buf->buffer, "\"");
e5eacc
 
e5eacc
 		while (IS_BLANK_CH(*tmp)) tmp++;
e5eacc
 
e5eacc
-		/* URI Escape everything, except server side includes. */
e5eacc
-		for ( ; ; ) {
e5eacc
-		    xmlChar *escaped;
e5eacc
-		    xmlChar endChar;
e5eacc
-		    xmlChar *end = NULL;
e5eacc
-		    xmlChar *start = (xmlChar *)xmlStrstr(tmp, BAD_CAST "
e5eacc
-		    if (start != NULL) {
e5eacc
-			end = (xmlChar *)xmlStrstr(tmp, BAD_CAST "-->");
e5eacc
-			if (end != NULL) {
e5eacc
-			    *start = '\0';
e5eacc
-			}
e5eacc
-		    }
e5eacc
-
e5eacc
-		    /* Escape the whole string, or until start (set to '\0'). */
e5eacc
-		    escaped = xmlURIEscapeStr(tmp, BAD_CAST"@/:=?;#%&,+");
e5eacc
-		    if (escaped != NULL) {
e5eacc
-		        xmlBufCat(buf->buffer, escaped);
e5eacc
-		        xmlFree(escaped);
e5eacc
-		    } else {
e5eacc
-		        xmlBufCat(buf->buffer, tmp);
e5eacc
-		    }
e5eacc
-
e5eacc
-		    if (end == NULL) { /* Everything has been written. */
e5eacc
-			break;
e5eacc
-		    }
e5eacc
-
e5eacc
-		    /* Do not escape anything within server side includes. */
e5eacc
-		    *start = '<'; /* Restore the first character of "
e5eacc
-		    end += 3; /* strlen("-->") */
e5eacc
-		    endChar = *end;
e5eacc
-		    *end = '\0';
e5eacc
-		    xmlBufCat(buf->buffer, start);
e5eacc
-		    *end = endChar;
e5eacc
-		    tmp = end;
e5eacc
+		/*
e5eacc
+		 * the < and > have already been escaped at the entity level
e5eacc
+		 * And doing so here breaks server side includes
e5eacc
+		 */
e5eacc
+		escaped = xmlURIEscapeStr(tmp, BAD_CAST"@/:=?;#%&,+<>");
e5eacc
+		if (escaped != NULL) {
e5eacc
+		    xmlBufWriteQuotedString(buf->buffer, escaped);
e5eacc
+		    xmlFree(escaped);
e5eacc
+		} else {
e5eacc
+		    xmlBufWriteQuotedString(buf->buffer, value);
e5eacc
 		}
e5eacc
-
e5eacc
-		xmlBufCCat(buf->buffer, "\"");
e5eacc
 	    } else {
e5eacc
 		xmlBufWriteQuotedString(buf->buffer, value);
e5eacc
 	    }
e5eacc
-- 
e5eacc
GitLab
e5eacc