Skip to content

Commit ee0daa5

Browse files
committed
Fix GH-17162: zend_array_try_init() with dtor can cause engine UAF
Closes GH-17167.
1 parent 0a3442f commit ee0daa5

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ PHP NEWS
44

55
- Core:
66
. Fixed bug GH-17106 (ZEND_MATCH_ERROR misoptimization). (ilutov)
7+
. Fixed bug GH-17162 (zend_array_try_init() with dtor can cause engine UAF).
8+
(nielsdos)
79

810
- DBA:
911
. Skip test if inifile is disabled. (orlitzky)

Zend/tests/gh17162.phpt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
GH-17162 (zend_array_try_init() with dtor can cause engine UAF)
3+
--FILE--
4+
<?php
5+
class Test {
6+
function __destruct() {
7+
global $box;
8+
$box->value = null;
9+
}
10+
}
11+
$box = [new Test];
12+
// Using getimagesize() for the test because it's always available,
13+
// but any function that uses zend_try_array_init() would work.
14+
try {
15+
getimagesize("dummy", $box);
16+
} catch (Error $e) {
17+
echo $e->getMessage(), "\n";
18+
}
19+
?>
20+
--EXPECT--
21+
Attempt to assign property "value" on null

Zend/zend_API.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1478,7 +1478,10 @@ static zend_always_inline zval *zend_try_array_init_size(zval *zv, uint32_t size
14781478
}
14791479
zv = &ref->val;
14801480
}
1481-
zval_ptr_dtor(zv);
1481+
zval garbage;
1482+
ZVAL_COPY_VALUE(&garbage, zv);
1483+
ZVAL_NULL(zv);
1484+
zval_ptr_dtor(&garbage);
14821485
ZVAL_ARR(zv, arr);
14831486
return zv;
14841487
}

0 commit comments

Comments
 (0)