Skip to content

Commit abf4c11

Browse files
committed
Fix getting the address of an uninitialized property of a SimpleXMLElement resulting in a crash
Closes GH-12945.
1 parent a6d17bf commit abf4c11

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ PHP NEWS
2323
- PHPDBG:
2424
. Fixed bug GH-12962 (Double free of init_file in phpdbg_prompt.c). (nielsdos)
2525

26+
- SimpleXML:
27+
. Fix getting the address of an uninitialized property of a SimpleXMLElement
28+
resulting in a crash. (nielsdos)
29+
2630
21 Dec 2023, PHP 8.2.14
2731

2832
- Core:

ext/simplexml/simplexml.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,9 @@ static zval *sxe_property_get_adr(zend_object *object, zend_string *zname, int f
636636

637637
sxe = php_sxe_fetch_object(object);
638638
GET_NODE(sxe, node);
639+
if (UNEXPECTED(!node)) {
640+
return &EG(error_zval);
641+
}
639642
name = ZSTR_VAL(zname);
640643
node = sxe_get_element_by_name(sxe, node, &name, &type);
641644
if (node) {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Getting the address of an uninitialized property of a SimpleXMLElement
3+
--EXTENSIONS--
4+
simplexml
5+
--FILE--
6+
<?php
7+
8+
$rc = new ReflectionClass('SimpleXMLElement');
9+
$sxe = $rc->newInstanceWithoutConstructor();
10+
$sxe->a['b'] = 'b';
11+
12+
?>
13+
--EXPECTF--
14+
Fatal error: Uncaught Error: SimpleXMLElement is not properly initialized in %s:%d
15+
Stack trace:
16+
#0 {main}
17+
thrown in %s on line %d

0 commit comments

Comments
 (0)