Skip to content

Commit 4fc336c

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2: Fix getting the address of an uninitialized property of a SimpleXMLElement resulting in a crash Fix GH-12962: Double free of init_file in phpdbg_prompt.c
2 parents 1b8be9a + abf4c11 commit 4fc336c

File tree

6 files changed

+43
-1
lines changed

6 files changed

+43
-1
lines changed

NEWS

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ PHP NEWS
2828
. Added workaround for SELinux mprotect execheap issue.
2929
See https://bugzilla.kernel.org/show_bug.cgi?id=218258. (ilutov)
3030

31+
- PHPDBG:
32+
. Fixed bug GH-12962 (Double free of init_file in phpdbg_prompt.c). (nielsdos)
33+
34+
- SimpleXML:
35+
. Fix getting the address of an uninitialized property of a SimpleXMLElement
36+
resulting in a crash. (nielsdos)
37+
3138
07 Dec 2023, PHP 8.3.1RC1
3239

3340
- Core:

ext/simplexml/simplexml.c

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

626626
sxe = php_sxe_fetch_object(object);
627627
GET_NODE(sxe, node);
628+
if (UNEXPECTED(!node)) {
629+
return &EG(error_zval);
630+
}
628631
name = ZSTR_VAL(zname);
629632
node = sxe_get_element_by_name(sxe, node, name, &type);
630633
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

sapi/phpdbg/phpdbg_prompt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ void phpdbg_init(char *init_file, size_t init_file_len, bool use_default) /* {{{
363363
}
364364

365365
ZEND_IGNORE_VALUE(asprintf(&init_file, "%s/%s", scan_dir, PHPDBG_INIT_FILENAME));
366-
phpdbg_try_file_init(init_file, strlen(init_file), 1);
366+
phpdbg_try_file_init(init_file, strlen(init_file), 0);
367367
free(init_file);
368368
if (i == -1) {
369369
break;

sapi/phpdbg/tests/gh12962.phpt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
GH-12962 (Double free of init_file in phpdbg_prompt.c)
3+
--SKIPIF--
4+
<?php
5+
if (!getenv('TEST_PHPDBG_EXECUTABLE')) die("SKIP: No TEST_PHPDBG_EXECUTABLE specified");
6+
?>
7+
--FILE--
8+
<?php
9+
putenv('PHP_INI_SCAN_DIR='.__DIR__."/gh12962");
10+
passthru($_ENV['TEST_PHPDBG_EXECUTABLE'] . " -q");
11+
?>
12+
--EXPECT--
13+
Executed .phpdbginit

sapi/phpdbg/tests/gh12962/.phpdbginit

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ev "Executed .phpdbginit"
2+
q

0 commit comments

Comments
 (0)