Skip to content

Commit

Permalink
Merge branch 'PHP-8.4'
Browse files Browse the repository at this point in the history
* PHP-8.4:
  Fix phpGH-16316: DOMXPath breaks when not initialized properly
  • Loading branch information
nielsdos committed Oct 10, 2024
2 parents 57bfca9 + 25d0661 commit c597f92
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
32 changes: 32 additions & 0 deletions ext/dom/tests/gh16316.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
--TEST--
GH-16316 (DOMXPath breaks when not initialized properly)
--EXTENSIONS--
dom
--FILE--
<?php

class Demo extends DOMXPath {
public function __construct() {}
}

$demo = new Demo;
try {
var_dump($demo);
} catch (DOMException $e) {
echo $e->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
5 changes: 5 additions & 0 deletions ext/dom/xpath.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ zend_result 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;
}
Expand Down

0 comments on commit c597f92

Please sign in to comment.