Skip to content

Commit

Permalink
Fix bug #81325 Segfault in zif_simplexml_import_dom
Browse files Browse the repository at this point in the history
  • Loading branch information
remicollet committed Aug 3, 2021
1 parent 6c7b322 commit 112527d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ext/simplexml/simplexml.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 19 additions & 0 deletions ext/simplexml/tests/bug81325.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
BUg #81325 (segfault in zif_simplexml_import_dom)
--SKIPIF--
<?php
if (!extension_loaded('simplexml')) die('skip simplexml not available');
if (!extension_loaded('dom')) die('skip simplexml not available');
?>
--FILE--
<?php
$dom = new DOMDocument;
$dom->loadXML("foo");
$xml = simplexml_import_dom($dom);
?>
Done
--EXPECTF--
Warning: DOMDocument::loadXML(): Start tag expected%s

Warning: simplexml_import_dom(): Invalid Nodetype%s
Done

0 comments on commit 112527d

Please sign in to comment.