Skip to content

Commit 3c4b34f

Browse files
committed
bug symfony#25755 [Debug] prevent infinite loop with faulty exception handlers (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 | symfony#25743 | License | MIT | Doc PR | - Commits ------- 5f397f8 [Debug] prevent infinite loop with faulty exception handlers
2 parents ae8b5a7 + 5f397f8 commit 3c4b34f

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/Symfony/Component/Debug/ErrorHandler.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,8 @@ public static function handleFatalError(array $error = null)
561561

562562
$handler = self::$reservedMemory = null;
563563
$handlers = array();
564+
$previousHandler = null;
565+
$sameHandlerLimit = 10;
564566

565567
while (!is_array($handler) || !$handler[0] instanceof self) {
566568
$handler = set_exception_handler('var_dump');
@@ -570,7 +572,14 @@ public static function handleFatalError(array $error = null)
570572
break;
571573
}
572574
restore_exception_handler();
573-
array_unshift($handlers, $handler);
575+
576+
if ($handler !== $previousHandler) {
577+
array_unshift($handlers, $handler);
578+
$previousHandler = $handler;
579+
} elseif (0 === --$sameHandlerLimit) {
580+
$handler = null;
581+
break;
582+
}
574583
}
575584
foreach ($handlers as $h) {
576585
set_exception_handler($h);

0 commit comments

Comments
 (0)