Skip to content

Commit 8f61854

Browse files
committed
Add a missing null check in simplexml
1 parent 8fbc618 commit 8f61854

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

ext/simplexml/simplexml.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,6 +1390,11 @@ SXE_METHOD(registerXPathNamespace)
13901390
}
13911391

13921392
sxe = Z_SXEOBJ_P(ZEND_THIS);
1393+
if (!sxe->document) {
1394+
zend_throw_error(NULL, "SimpleXMLElement is not properly initialized");
1395+
RETURN_THROWS();
1396+
}
1397+
13931398
if (!sxe->xpath) {
13941399
sxe->xpath = xmlXPathNewContext((xmlDocPtr) sxe->document->ptr);
13951400
}

ext/simplexml/tests/simplexml_uninitialized.phpt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ try {
3535
} catch (Error $e) {
3636
echo $e->getMessage(), "\n";
3737
}
38+
try {
39+
var_dump($sxe->registerXPathNamespace('', ''));
40+
} catch (Error $e) {
41+
echo $e->getMessage(), "\n";
42+
}
3843
try {
3944
var_dump($sxe->foo);
4045
} catch (Error $e) {
@@ -49,3 +54,4 @@ SimpleXMLElement is not properly initialized
4954
SimpleXMLElement is not properly initialized
5055
SimpleXMLElement is not properly initialized
5156
SimpleXMLElement is not properly initialized
57+
SimpleXMLElement is not properly initialized

0 commit comments

Comments
 (0)