diff --git a/NEWS b/NEWS index dc9f6e10dc12c..a3363b0229908 100644 --- a/NEWS +++ b/NEWS @@ -9,6 +9,10 @@ PHP NEWS . Fixed bug GH-16302 (CurlMultiHandle holds a reference to CurlHandle if curl_multi_add_handle fails). (timwolla) +- DOM: + . Fixed bug GH-16316 (DOMXPath breaks when not initialized properly). + (nielsdos) + - PHPDBG: . Fixed bug GH-16174 (Empty string is an invalid expression for ev). (cmb) diff --git a/ext/dom/tests/gh16316.phpt b/ext/dom/tests/gh16316.phpt new file mode 100644 index 0000000000000..43368746bc462 --- /dev/null +++ b/ext/dom/tests/gh16316.phpt @@ -0,0 +1,32 @@ +--TEST-- +GH-16316 (DOMXPath breaks when not initialized properly) +--EXTENSIONS-- +dom +--FILE-- +getMessage(), "\n"; +} + +try { + var_dump($demo->document); +} catch (DOMException $e) { + echo $e->getMessage(), "\n"; +} + +?> +--EXPECT-- +object(Demo)#1 (1) { + ["registerNodeNamespaces"]=> + bool(true) +} +Invalid State Error +Invalid State Error diff --git a/ext/dom/xpath.c b/ext/dom/xpath.c index 22a7e0ecc5a91..cad08e0a8d8a6 100644 --- a/ext/dom/xpath.c +++ b/ext/dom/xpath.c @@ -264,6 +264,11 @@ int dom_xpath_document_read(dom_object *obj, zval *retval) docp = (xmlDocPtr) ctx->doc; } + if (UNEXPECTED(!docp)) { + php_dom_throw_error(INVALID_STATE_ERR, /* strict */ true); + return FAILURE; + } + php_dom_create_object((xmlNodePtr) docp, retval, obj); return SUCCESS; }