diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index ad6b85368f..2c7d3de736 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -113,17 +113,22 @@ class Application } else { $this->renderException($e, $output); } - $statusCode = $e->getCode(); - $statusCode = is_numeric($statusCode) && $statusCode ? (int) $statusCode : 1; + $statusCode = $e->getCode(); + if (is_numeric($statusCode)) { + $statusCode = (int) $statusCode; + if (0 === $statusCode) { + $statusCode = 1; + } + } else { + $statusCode = 1; + } } if ($this->autoExit) { - if ($statusCode > 255) { - $statusCode = 255; - } + // ensure exit code is between 0-254 (255 is reserved by PHP and should not be used) // @codeCoverageIgnoreStart - exit($statusCode); + exit(max(0, min(254, $statusCode))); // @codeCoverageIgnoreEnd }