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

Skip to content

[HttpKernel] Avoid unsuppressed include #36473

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions src/Symfony/Component/HttpKernel/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -428,16 +428,12 @@ protected function initializeContainer()
$cache = new ConfigCache($cacheDir.'/'.$class.'.php', $this->debug);
$cachePath = $cache->getPath();

// Silence E_WARNING to ignore "include" failures - don't use "@" to prevent silencing fatal errors
$errorLevel = error_reporting(E_ALL ^ E_WARNING);

try {
if (file_exists($cachePath) && \is_object($this->container = include $cachePath)
if (\is_object($this->container = $this->includeSafe($cachePath))
&& (!$this->debug || (self::$freshCache[$cachePath] ?? $cache->isFresh()))
) {
self::$freshCache[$cachePath] = true;
$this->container->set('kernel', $this);
error_reporting($errorLevel);

return;
}
Expand All @@ -455,7 +451,7 @@ protected function initializeContainer()
if (!flock($lock, $wouldBlock ? LOCK_SH : LOCK_EX)) {
fclose($lock);
$lock = null;
} elseif (!\is_object($this->container = include $cachePath)) {
} elseif (!\is_object($this->container = $this->includeSafe($cachePath))) {
$this->container = null;
} elseif (!$oldContainer || \get_class($this->container) !== $oldContainer->name) {
flock($lock, LOCK_UN);
Expand All @@ -466,8 +462,6 @@ protected function initializeContainer()
}
}
} catch (\Throwable $e) {
} finally {
error_reporting($errorLevel);
}

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

/**
* Silence E_WARNING to ignore "include" failures - don't use "@" to prevent silencing fatal errors.
*
* @return mixed
*/
private function includeSafe(string $path)
{
$errorLevel = error_reporting(E_ALL ^ E_WARNING);
try {
$result = include $path;
} finally {
error_reporting($errorLevel);
}

return $result;
}

/**
* @return array
*/
Expand Down