1From 0aa8652e596a20e95ed334ac65cf15e6e9ec4b3b Mon Sep 17 00:00:00 2001
2From: Nick Wellnhofer <wellnhofer@aevum.de>
3Date: Fri, 20 May 2022 14:54:49 +0200
4Subject: [PATCH 291/300] Use xmlNewDocText in xmlXIncludeCopyRange
5
6Otherwise, the initial node of the copy could be a text node with a
7NULL document. This results in the NULL document being propagated to
8copies of other nodes, losing information about the dictionary in which
9node data is stored, and freeing a dict-allocated string.
10
11See discussion in !175.
12
13Reference:https://github.com/GNOME/libxml2/commit/0aa8652e596a20e95ed334ac65cf15e6e9ec4b3b
14Conflict:NA
15
16---
17 xinclude.c | 8 ++++----
18 1 file changed, 4 insertions(+), 4 deletions(-)
19
20diff --git a/xinclude.c b/xinclude.c
21index e5fdf0f..8c14a68 100644
22--- a/xinclude.c
23+++ b/xinclude.c
24@@ -987,7 +987,7 @@ xmlXIncludeCopyRange(xmlXIncludeCtxtPtr ctxt, xmlDocPtr target,
25 		int len;
26 
27 		if (content == NULL) {
28-		    tmp = xmlNewTextLen(NULL, 0);
29+		    tmp = xmlNewDocTextLen(target, NULL, 0);
30 		} else {
31 		    len = index2;
32 		    if ((cur == start) && (index1 > 1)) {
33@@ -996,7 +996,7 @@ xmlXIncludeCopyRange(xmlXIncludeCtxtPtr ctxt, xmlDocPtr target,
34 		    } else {
35 			len = index2;
36 		    }
37-		    tmp = xmlNewTextLen(content, len);
38+		    tmp = xmlNewDocTextLen(target, content, len);
39 		}
40 		/* single sub text node selection */
41 		if (list == NULL)
42@@ -1047,13 +1047,13 @@ xmlXIncludeCopyRange(xmlXIncludeCtxtPtr ctxt, xmlDocPtr target,
43 		const xmlChar *content = cur->content;
44 
45 		if (content == NULL) {
46-		    tmp = xmlNewTextLen(NULL, 0);
47+		    tmp = xmlNewDocTextLen(target, NULL, 0);
48 		} else {
49 		    if (index1 > 1) {
50 			content += (index1 - 1);
51 			index1 = 0;
52 		    }
53-		    tmp = xmlNewText(content);
54+		    tmp = xmlNewDocText(target, content);
55 		}
56 		last = list = tmp;
57 		listParent = cur->parent;
58-- 
592.27.0
60
61