1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-01-19 10:03:34 +03:00

Use xmlNewDocText in xmlXIncludeCopyRange

Otherwise, the initial node of the copy could be a text node with a
NULL document. This results in the NULL document being propagated to
copies of other nodes, losing information about the dictionary in which
node data is stored, and freeing a dict-allocated string.

See discussion in !175.
This commit is contained in:
Nick Wellnhofer 2022-05-20 14:54:49 +02:00
parent 351dbdfe8b
commit 0aa8652e59

View File

@ -988,7 +988,7 @@ xmlXIncludeCopyRange(xmlXIncludeCtxtPtr ctxt, xmlDocPtr target,
int len;
if (content == NULL) {
tmp = xmlNewTextLen(NULL, 0);
tmp = xmlNewDocTextLen(target, NULL, 0);
} else {
len = index2;
if ((cur == start) && (index1 > 1)) {
@ -997,7 +997,7 @@ xmlXIncludeCopyRange(xmlXIncludeCtxtPtr ctxt, xmlDocPtr target,
} else {
len = index2;
}
tmp = xmlNewTextLen(content, len);
tmp = xmlNewDocTextLen(target, content, len);
}
/* single sub text node selection */
if (list == NULL)
@ -1048,13 +1048,13 @@ xmlXIncludeCopyRange(xmlXIncludeCtxtPtr ctxt, xmlDocPtr target,
const xmlChar *content = cur->content;
if (content == NULL) {
tmp = xmlNewTextLen(NULL, 0);
tmp = xmlNewDocTextLen(target, NULL, 0);
} else {
if (index1 > 1) {
content += (index1 - 1);
index1 = 0;
}
tmp = xmlNewText(content);
tmp = xmlNewDocText(target, content);
}
last = list = tmp;
listParent = cur->parent;