mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
Fix leak when setting cyclic previous exception in finally
A curious exception handling pattern found in Symfony's HttpClient.
This commit is contained in:
20
Zend/tests/exception_set_previous_leak.phpt
Normal file
20
Zend/tests/exception_set_previous_leak.phpt
Normal file
@@ -0,0 +1,20 @@
|
||||
--TEST--
|
||||
Leak when setting recursive previous exception in finally handling
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
try {
|
||||
try {
|
||||
throw new Exception("Test");
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
} finally {
|
||||
throw $e;
|
||||
}
|
||||
} catch (Exception $e2) {
|
||||
echo $e2->getMessage(), "\n";
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
Test
|
||||
@@ -76,9 +76,15 @@ void zend_exception_set_previous(zend_object *exception, zend_object *add_previo
|
||||
zval pv, zv, rv;
|
||||
zend_class_entry *base_ce;
|
||||
|
||||
if (exception == add_previous || !add_previous || !exception) {
|
||||
if (!exception || !add_previous) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (exception == add_previous) {
|
||||
OBJ_RELEASE(add_previous);
|
||||
return;
|
||||
}
|
||||
|
||||
ZVAL_OBJ(&pv, add_previous);
|
||||
if (!instanceof_function(Z_OBJCE(pv), zend_ce_throwable)) {
|
||||
zend_error_noreturn(E_CORE_ERROR, "Previous exception must implement Throwable");
|
||||
|
||||
Reference in New Issue
Block a user