[Debug] prevent infinite loop with faulty exception handlers

This commit is contained in:
Nicolas Grekas 2018-01-10 19:03:23 +01:00
parent fad59b3ce7
commit 5f397f8dcf
1 changed files with 10 additions and 1 deletions

View File

@ -561,6 +561,8 @@ class ErrorHandler
$handler = self::$reservedMemory = null;
$handlers = array();
$previousHandler = null;
$sameHandlerLimit = 10;
while (!is_array($handler) || !$handler[0] instanceof self) {
$handler = set_exception_handler('var_dump');
@ -570,7 +572,14 @@ class ErrorHandler
break;
}
restore_exception_handler();
array_unshift($handlers, $handler);
if ($handler !== $previousHandler) {
array_unshift($handlers, $handler);
$previousHandler = $handler;
} elseif (0 === --$sameHandlerLimit) {
$handler = null;
break;
}
}
foreach ($handlers as $h) {
set_exception_handler($h);