summaryrefslogtreecommitdiff
path: root/tree.c
diff options
context:
space:
mode:
authorNick Wellnhofer <wellnhofer@aevum.de>2022-02-07 22:09:25 +0100
committerNick Wellnhofer <wellnhofer@aevum.de>2022-02-07 22:18:27 +0100
commit57b3abd592373ad9e4aacdbf41e00612afb2ccf7 (patch)
tree3504b4d3ca4e6e15b879797e1ace78022759692f /tree.c
parent8be44aeb16704f5f8a1355523b72402d7bb99b16 (diff)
downloadlibxml2-57b3abd592373ad9e4aacdbf41e00612afb2ccf7.tar.gz
Fix xmlSetTreeDoc with entity references
The children member of entity reference nodes points to the entity declaration and must never be followed when traversing a tree. In the worst case, this could lead to an infinite loop. It's somewhat unclear how moving entity references to other documents should work exactly. For now we simply set the children pointer to NULL to avoid a reference to the original document. Fixes #42.
Diffstat (limited to 'tree.c')
-rw-r--r--tree.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/tree.c b/tree.c
index 96d3f324..9d94aa42 100644
--- a/tree.c
+++ b/tree.c
@@ -2856,8 +2856,15 @@ xmlSetTreeDoc(xmlNodePtr tree, xmlDocPtr doc) {
prop = prop->next;
}
}
- if (tree->children != NULL)
+ if (tree->type == XML_ENTITY_REF_NODE) {
+ /*
+ * Clear 'children' which points to the entity declaration
+ * from the original document.
+ */
+ tree->children = NULL;
+ } else if (tree->children != NULL) {
xmlSetListDoc(tree->children, doc);
+ }
tree->doc = doc;
}
}