summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Wellnhofer <wellnhofer@aevum.de>2020-09-29 18:08:37 +0200
committerNick Wellnhofer <wellnhofer@aevum.de>2020-09-29 18:08:37 +0200
commit0b3c64d9f2f3e9ce1a98d8f19ee7a763c87e27d5 (patch)
tree96b3cc07b461dd2095e2edd353b192f6999128df
parent847a3a1181d59dc49c1b446d646d344d0543af3e (diff)
downloadlibxml2-0b3c64d9f2f3e9ce1a98d8f19ee7a763c87e27d5.tar.gz
Handle dumps of corrupted documents more gracefully
Check parent pointers for NULL after the non-recursive rewrite of the serialization code. This avoids segfaults with corrupted documents which can apparently be seen with lxml, see issue #187.
-rw-r--r--HTMLtree.c6
-rw-r--r--xmlsave.c12
2 files changed, 18 insertions, 0 deletions
diff --git a/HTMLtree.c b/HTMLtree.c
index cdb7f86a..8d0c7795 100644
--- a/HTMLtree.c
+++ b/HTMLtree.c
@@ -903,6 +903,12 @@ htmlNodeDumpFormatOutput(xmlOutputBufferPtr buf, xmlDocPtr doc,
break;
}
+ /*
+ * The parent should never be NULL here but we want to handle
+ * corrupted documents gracefully.
+ */
+ if (cur->parent == NULL)
+ return;
cur = cur->parent;
if ((cur->type == XML_HTML_DOCUMENT_NODE) ||
diff --git a/xmlsave.c b/xmlsave.c
index 2225628d..61a40459 100644
--- a/xmlsave.c
+++ b/xmlsave.c
@@ -1058,6 +1058,12 @@ xmlNodeDumpOutputInternal(xmlSaveCtxtPtr ctxt, xmlNodePtr cur) {
break;
}
+ /*
+ * The parent should never be NULL here but we want to handle
+ * corrupted documents gracefully.
+ */
+ if (cur->parent == NULL)
+ return;
cur = cur->parent;
if (cur->type == XML_ELEMENT_NODE) {
@@ -1686,6 +1692,12 @@ xhtmlNodeDumpOutput(xmlSaveCtxtPtr ctxt, xmlNodePtr cur) {
break;
}
+ /*
+ * The parent should never be NULL here but we want to handle
+ * corrupted documents gracefully.
+ */
+ if (cur->parent == NULL)
+ return;
cur = cur->parent;
if (cur->type == XML_ELEMENT_NODE) {