diff --git a/support/PhabricatorStartup.php b/support/PhabricatorStartup.php index 3465656818..3945049ffb 100644 --- a/support/PhabricatorStartup.php +++ b/support/PhabricatorStartup.php @@ -425,7 +425,8 @@ final class PhabricatorStartup { $_POST = array_merge($_POST, $filtered); break; case INPUT_ENV; - $_ENV = array_merge($_ENV, $filtered); + $env = array_merge($_ENV, $filtered); + $_ENV = self::filterEnvSuperglobal($env); break; } } @@ -458,6 +459,30 @@ final class PhabricatorStartup { } } + + /** + * Adjust `$_ENV` before execution. + * + * Adjustments here primarily impact the environment as seen by subprocesses. + * The environment is forwarded explicitly by @{class:ExecFuture}. + * + * @param map Input `$_ENV`. + * @return map Suitable `$_ENV`. + * @task validation + */ + private static function filterEnvSuperglobal(array $env) { + + // In some configurations, we may get "argc" and "argv" set in $_ENV. + // These are not real environmental variables, and "argv" may have an array + // value which can not be forwarded to subprocesses. Remove these from the + // environment if they are present. + unset($env['argc']); + unset($env['argv']); + + return $env; + } + + /** * @task validation */