Skip to content

Commit 1371f50

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Fix GH-17162: zend_array_try_init() with dtor can cause engine UAF
2 parents fa8c6a5 + 08b14a5 commit 1371f50

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

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
@@ -1485,7 +1485,10 @@ static zend_always_inline zval *zend_try_array_init_size(zval *zv, uint32_t size
14851485
}
14861486
zv = &ref->val;
14871487
}
1488-
zval_ptr_dtor(zv);
1488+
zval garbage;
1489+
ZVAL_COPY_VALUE(&garbage, zv);
1490+
ZVAL_NULL(zv);
1491+
zval_ptr_dtor(&garbage);
14891492
ZVAL_ARR(zv, arr);
14901493
return zv;
14911494
}

0 commit comments

Comments
 (0)