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
25 changes: 25 additions & 0 deletions Zend/tests/property_hooks/get_object_vars_hook_exception_leak.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--TEST--
get_object_vars() releases the value of a get hook that raises an exception
--FILE--
<?php
class Thrower {
function __destruct() {
throw new Exception('destructor');
}
}
class Hooked {
public string $prop {
get {
$local = new Thrower;
return str_repeat('y', 100);
}
}
}
try {
get_object_vars(new Hooked);
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECT--
destructor
1 change: 1 addition & 0 deletions Zend/zend_builtin_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,7 @@ ZEND_FUNCTION(get_object_vars)
value = zend_read_property_ex(prop_info->ce, zobj, unmangled_name, /* silent */ true, &tmp);
zend_string_release_ex(unmangled_name, false);
if (EG(exception)) {
zval_ptr_dtor(&tmp);
zend_release_properties(properties);
zval_ptr_dtor(return_value);
ZVAL_UNDEF(return_value);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--TEST--
var_export() releases the value of a get hook that raises an exception
--FILE--
<?php
class Thrower {
function __destruct() {
throw new Exception('destructor');
}
}
class Hooked {
public string $prop {
get {
$local = new Thrower;
return str_repeat('y', 100);
}
}
}
try {
var_export(new Hooked);
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECT--
destructor
3 changes: 3 additions & 0 deletions ext/standard/var.c
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,9 @@ PHPAPI zend_result php_var_export_ex(zval *struc, int level, smart_str *buf) /*
val = zend_read_property_ex(prop_info->ce, zobj, unmangled_name, /* silent */ true, &tmp);
zend_string_release_ex(unmangled_name, false);
if (EG(exception)) {
if (val == &tmp) {
zval_ptr_dtor(&tmp);
}
ZEND_GUARD_OR_GC_UNPROTECT_RECURSION(guard, EXPORT, zobj);
zend_release_properties(myht);
return FAILURE;
Expand Down
Loading