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

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