Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6db274e

Browse files
committed
Fix #36472: Avoid unsuppressed include
1 parent 6f81e03 commit 6db274e

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/Symfony/Component/HttpKernel/Kernel.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -428,16 +428,12 @@ protected function initializeContainer()
428428
$cache = new ConfigCache($cacheDir.'/'.$class.'.php', $this->debug);
429429
$cachePath = $cache->getPath();
430430

431-
// Silence E_WARNING to ignore "include" failures - don't use "@" to prevent silencing fatal errors
432-
$errorLevel = error_reporting(E_ALL ^ E_WARNING);
433-
434431
try {
435-
if (file_exists($cachePath) && \is_object($this->container = include $cachePath)
432+
if (\is_object($this->container = $this->includeSafe($cachePath))
436433
&& (!$this->debug || (self::$freshCache[$cachePath] ?? $cache->isFresh()))
437434
) {
438435
self::$freshCache[$cachePath] = true;
439436
$this->container->set('kernel', $this);
440-
error_reporting($errorLevel);
441437

442438
return;
443439
}
@@ -455,7 +451,7 @@ protected function initializeContainer()
455451
if (!flock($lock, $wouldBlock ? LOCK_SH : LOCK_EX)) {
456452
fclose($lock);
457453
$lock = null;
458-
} elseif (!\is_object($this->container = include $cachePath)) {
454+
} elseif (!\is_object($this->container = $this->includeSafe($cachePath))) {
459455
$this->container = null;
460456
} elseif (!$oldContainer || \get_class($this->container) !== $oldContainer->name) {
461457
flock($lock, LOCK_UN);
@@ -466,8 +462,6 @@ protected function initializeContainer()
466462
}
467463
}
468464
} catch (\Throwable $e) {
469-
} finally {
470-
error_reporting($errorLevel);
471465
}
472466

473467
if ($collectDeprecations = $this->debug && !\defined('PHPUNIT_COMPOSER_INSTALL')) {
@@ -789,6 +783,23 @@ public static function stripComments(string $source)
789783
return $output;
790784
}
791785

786+
/**
787+
* Silence E_WARNING to ignore "include" failures - don't use "@" to prevent silencing fatal errors.
788+
*
789+
* @return mixed
790+
*/
791+
private function includeSafe(string $path)
792+
{
793+
$errorLevel = error_reporting(E_ALL ^ E_WARNING);
794+
try {
795+
$result = include $path;
796+
} finally {
797+
error_reporting($errorLevel);
798+
}
799+
800+
return $result;
801+
}
802+
792803
/**
793804
* @return array
794805
*/

0 commit comments

Comments
 (0)