From 52b9e5ec142337462463be14c3c62762d9f2347a Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 27 Apr 2015 05:21:15 -0700 Subject: [PATCH] Filter potentially problematic $_ENV variables Summary: Caught this in the production error logs. We can end up with `argv` defined and set to an array in an nginx + php-fpm configuration. When we later run `ExecFuture` subprocesses, they won't be able to forward the value. The error this produces looks like this: ``` 015/04/27 12:17:35 [error] 10948#0: *674 FastCGI sent in stderr: "PHP message: [2015-04-27 12:17:35] ERROR 8: Array to string conversion at [/core/lib/libphutil/src/future/exec/ExecFuture.php:667] PHP message: arcanist(head=master, ref.master=805ae12408e8), phabricator(head=master, ref.master=8ce8a761efe9), phutil(head=master, ref.master=fccf03d48e08) PHP message: #0 ExecFuture::isReady() called at [/src/future/Future.php:39] PHP message: #1 Future::resolve(NULL) called at [/src/future/exec/ExecFuture.php:413] PHP message: #2 ExecFuture::resolvex() called at [/src/applications/diffusion/query/rawdiff/DiffusionGitRawDiffQuery.php:40] PHP message: #3 DiffusionGitRawDiffQuery::executeQuery() called at [/src/applications/diffusion/query/rawdiff/DiffusionRawDiffQuery.php:17] PHP message: #4 DiffusionRawDiffQuery::loadRawDiff() called at [/src/applications/diffusion/conduit/DiffusionRawDiffQueryConduitAPIMethod.php:56] PHP message: #5 DiffusionRawDiffQueryConduitAPIMethod::getResult(ConduitAPIRequest) called at [/src/applications/diffusion/conduit/DiffusionQueryConduitAPIMethod.php:135] PHP message: #6 DiffusionQueryConduitAPIMethod::execute(ConduitAPIRequest) called at [/src/applications/conduit/method/ConduitAPIMethod.php:90] PHP message: #7 ConduitAPIMethod::executeMethod(ConduitAPIRequest) called at [/src/applications/conduit/call/ConduitCall.php:134] PHP message: #8 ConduitCall::executeMethod() called at [/src/applications/conduit/call/ConduitCall.php:84] PHP message: #9 ConduitCall::execute() called at [/src/applications/diffusion/query/DiffusionQuery.php:81] PHP message: #10 DiffusionQuery::callConduitWithDiffusionRequest(PhabricatorUser, DiffusionGitRequest, string, array) called at [/src/applications/diffusion/controller/DiffusionController.php:184] PHP message: #11 DiffusionController::callConduitWithDiffusionRequest(string, array) called at [ 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 */