From: Nikita Popov Date: Thu, 13 Aug 2020 14:34:56 +0000 (+0200) Subject: Add a missing null check in simplexml X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8f61854108a916938095eccaad078b9c53078d4d;p=php Add a missing null check in simplexml --- diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c index 4688fed5b4..afd655aeed 100644 --- a/ext/simplexml/simplexml.c +++ b/ext/simplexml/simplexml.c @@ -1390,6 +1390,11 @@ SXE_METHOD(registerXPathNamespace) } sxe = Z_SXEOBJ_P(ZEND_THIS); + if (!sxe->document) { + zend_throw_error(NULL, "SimpleXMLElement is not properly initialized"); + RETURN_THROWS(); + } + if (!sxe->xpath) { sxe->xpath = xmlXPathNewContext((xmlDocPtr) sxe->document->ptr); } diff --git a/ext/simplexml/tests/simplexml_uninitialized.phpt b/ext/simplexml/tests/simplexml_uninitialized.phpt index 9361f232a1..0c6cfd1e1e 100644 --- a/ext/simplexml/tests/simplexml_uninitialized.phpt +++ b/ext/simplexml/tests/simplexml_uninitialized.phpt @@ -35,6 +35,11 @@ try { } catch (Error $e) { echo $e->getMessage(), "\n"; } +try { + var_dump($sxe->registerXPathNamespace('', '')); +} catch (Error $e) { + echo $e->getMessage(), "\n"; +} try { var_dump($sxe->foo); } catch (Error $e) { @@ -49,3 +54,4 @@ SimpleXMLElement is not properly initialized SimpleXMLElement is not properly initialized SimpleXMLElement is not properly initialized SimpleXMLElement is not properly initialized +SimpleXMLElement is not properly initialized