Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
22 changes: 22 additions & 0 deletions Zend/tests/gh17162.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--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 stdClass();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I don't think this stdClass is needed? Technically it should be an array, should have the same result. This doesn't fail because $image_info only has a doc-block type.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah fair, forgot this when I changed it from an mbstring function to this one, I'll change it.

$box->value = 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