Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Zend/tests/gh17162.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
GH-17162 (zend_array_try_init() with dtor can cause engine UAF)
--FILE--
<?php
class Test {
function __destruct() {
global $box;
$box->value = null;
}
}
$box = [new Test];
// Using getimagesize() for the test because it's always available,
// but any function that uses zend_try_array_init() would work.
try {
getimagesize("dummy", $box);
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECT--
Attempt to assign property "value" on null
5 changes: 4 additions & 1 deletion Zend/zend_API.h
Original file line number Diff line number Diff line change
Expand Up @@ -1478,7 +1478,10 @@ static zend_always_inline zval *zend_try_array_init_size(zval *zv, uint32_t size
}
zv = &ref->val;
}
zval_ptr_dtor(zv);
zval garbage;
ZVAL_COPY_VALUE(&garbage, zv);
ZVAL_NULL(zv);
zval_ptr_dtor(&garbage);
ZVAL_ARR(zv, arr);
return zv;
}
Expand Down
Loading