Skip to content

Commit 25d0661

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: Fix phpGH-16316: DOMXPath breaks when not initialized properly
2 parents 279e952 + 5ae7927 commit 25d0661

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ PHP NEWS
99
. Fixed bug GH-16302 (CurlMultiHandle holds a reference to CurlHandle if
1010
curl_multi_add_handle fails). (timwolla)
1111

12+
- DOM:
13+
. Fixed bug GH-16316 (DOMXPath breaks when not initialized properly).
14+
(nielsdos)
15+
1216
- PHPDBG:
1317
. Fixed bug GH-16174 (Empty string is an invalid expression for ev). (cmb)
1418

ext/dom/tests/gh16316.phpt

Lines changed: 32 additions & 0 deletions
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

Lines changed: 5 additions & 0 deletions
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)