From f2bec5b49375235fd8a1c2fe51e49480382e5cbb Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Tue, 3 Aug 2021 11:40:47 +0200 Subject: [PATCH 1/2] Fix bug #81325 Segfault in zif_simplexml_import_dom --- ext/simplexml/simplexml.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c index 4ed41d7587626..21e1190e681b0 100644 --- a/ext/simplexml/simplexml.c +++ b/ext/simplexml/simplexml.c @@ -2635,7 +2635,7 @@ PHP_FUNCTION(simplexml_import_dom) nodep = xmlDocGetRootElement((xmlDocPtr) nodep); } - if (nodep->type == XML_ELEMENT_NODE) { + if (nodep && nodep->type == XML_ELEMENT_NODE) { if (!ce) { ce = sxe_class_entry; fptr_count = NULL; From 815ed4c928a959a42026f5977dc933b450120371 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Tue, 3 Aug 2021 11:56:31 +0200 Subject: [PATCH 2/2] add test --- ext/simplexml/tests/bug81325.phpt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 ext/simplexml/tests/bug81325.phpt diff --git a/ext/simplexml/tests/bug81325.phpt b/ext/simplexml/tests/bug81325.phpt new file mode 100644 index 0000000000000..b4010dd1f0c37 --- /dev/null +++ b/ext/simplexml/tests/bug81325.phpt @@ -0,0 +1,19 @@ +--TEST-- +BUg #81325 (segfault in zif_simplexml_import_dom) +--SKIPIF-- + +--FILE-- +loadXML("foo"); +$xml = simplexml_import_dom($dom); +?> +Done +--EXPECTF-- +Warning: DOMDocument::loadXML(): Start tag expected%s + +Warning: simplexml_import_dom(): Invalid Nodetype%s +Done