diff options
author | Nick Wellnhofer <wellnhofer@aevum.de> | 2020-09-29 18:08:37 +0200 |
---|---|---|
committer | Nick Wellnhofer <wellnhofer@aevum.de> | 2020-09-29 18:08:37 +0200 |
commit | 0b3c64d9f2f3e9ce1a98d8f19ee7a763c87e27d5 (patch) | |
tree | 96b3cc07b461dd2095e2edd353b192f6999128df | |
parent | 847a3a1181d59dc49c1b446d646d344d0543af3e (diff) | |
download | libxml2-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.c | 6 | ||||
-rw-r--r-- | xmlsave.c | 12 |
2 files changed, 18 insertions, 0 deletions
@@ -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) || @@ -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) { |