Skip to content

Commit

Permalink
bug #25755 [Debug] prevent infinite loop with faulty exception handle…
Browse files Browse the repository at this point in the history
…rs (nicolas-grekas)

This PR was merged into the 2.7 branch.

Discussion
----------

[Debug] prevent infinite loop with faulty exception handlers

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #25743
| License       | MIT
| Doc PR        | -

Commits
-------

5f397f8 [Debug] prevent infinite loop with faulty exception handlers
  • Loading branch information
fabpot committed Jan 13, 2018
2 parents ae8b5a7 + 5f397f8 commit 3c4b34f
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Symfony/Component/Debug/ErrorHandler.php
Expand Up @@ -561,6 +561,8 @@ public static function handleFatalError(array $error = null)

$handler = self::$reservedMemory = null;
$handlers = array();
$previousHandler = null;
$sameHandlerLimit = 10;

while (!is_array($handler) || !$handler[0] instanceof self) {
$handler = set_exception_handler('var_dump');
Expand All @@ -570,7 +572,14 @@ public static function handleFatalError(array $error = null)
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);
Expand Down

0 comments on commit 3c4b34f

Please sign in to comment.