diff options
author | Nick Wellnhofer <wellnhofer@aevum.de> | 2022-02-07 22:09:25 +0100 |
---|---|---|
committer | Nick Wellnhofer <wellnhofer@aevum.de> | 2022-02-07 22:18:27 +0100 |
commit | 57b3abd592373ad9e4aacdbf41e00612afb2ccf7 (patch) | |
tree | 3504b4d3ca4e6e15b879797e1ace78022759692f /tree.c | |
parent | 8be44aeb16704f5f8a1355523b72402d7bb99b16 (diff) | |
download | libxml2-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.c | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -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; } } |