Skip to content

Commit c597f92

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Fix phpGH-16316: DOMXPath breaks when not initialized properly
2 parents 57bfca9 + 25d0661 commit c597f92

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

ext/dom/tests/gh16316.phpt

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--TEST--
2+
GH-16316 (DOMXPath breaks when not initialized properly)
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
8+
class Demo extends DOMXPath {
9+
public function __construct() {}
10+
}
11+
12+
$demo = new Demo;
13+
try {
14+
var_dump($demo);
15+
} catch (DOMException $e) {
16+
echo $e->getMessage(), "\n";
17+
}
18+
19+
try {
20+
var_dump($demo->document);
21+
} catch (DOMException $e) {
22+
echo $e->getMessage(), "\n";
23+
}
24+
25+
?>
26+
--EXPECT--
27+
object(Demo)#1 (1) {
28+
["registerNodeNamespaces"]=>
29+
bool(true)
30+
}
31+
Invalid State Error
32+
Invalid State Error

ext/dom/xpath.c

+5
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ zend_result dom_xpath_document_read(dom_object *obj, zval *retval)
178178
docp = (xmlDocPtr) ctx->doc;
179179
}
180180

181+
if (UNEXPECTED(!docp)) {
182+
php_dom_throw_error(INVALID_STATE_ERR, /* strict */ true);
183+
return FAILURE;
184+
}
185+
181186
php_dom_create_object((xmlNodePtr) docp, retval, obj);
182187
return SUCCESS;
183188
}

0 commit comments

Comments
 (0)