Skip to content

Commit 112527d

Browse files
committed
Fix bug #81325 Segfault in zif_simplexml_import_dom
1 parent 6c7b322 commit 112527d

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

ext/simplexml/simplexml.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2635,7 +2635,7 @@ PHP_FUNCTION(simplexml_import_dom)
26352635
nodep = xmlDocGetRootElement((xmlDocPtr) nodep);
26362636
}
26372637

2638-
if (nodep->type == XML_ELEMENT_NODE) {
2638+
if (nodep && nodep->type == XML_ELEMENT_NODE) {
26392639
if (!ce) {
26402640
ce = sxe_class_entry;
26412641
fptr_count = NULL;

ext/simplexml/tests/bug81325.phpt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
BUg #81325 (segfault in zif_simplexml_import_dom)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('simplexml')) die('skip simplexml not available');
6+
if (!extension_loaded('dom')) die('skip simplexml not available');
7+
?>
8+
--FILE--
9+
<?php
10+
$dom = new DOMDocument;
11+
$dom->loadXML("foo");
12+
$xml = simplexml_import_dom($dom);
13+
?>
14+
Done
15+
--EXPECTF--
16+
Warning: DOMDocument::loadXML(): Start tag expected%s
17+
18+
Warning: simplexml_import_dom(): Invalid Nodetype%s
19+
Done

0 commit comments

Comments
 (0)