@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 [<phutil>/src/future/Future.php:39]
PHP message: #1 Future::resolve(NULL) called at [<phutil>/src/future/exec/ExecFuture.php:413]
PHP message: #2 ExecFuture::resolvex() called at [<phabricator>/src/applications/diffusion/query/rawdiff/DiffusionGitRawDiffQuery.php:40]
PHP message: #3 DiffusionGitRawDiffQuery::executeQuery() called at [<phabricator>/src/applications/diffusion/query/rawdiff/DiffusionRawDiffQuery.php:17]
PHP message: #4 DiffusionRawDiffQuery::loadRawDiff() called at [<phabricator>/src/applications/diffusion/conduit/DiffusionRawDiffQueryConduitAPIMethod.php:56]
PHP message: #5 DiffusionRawDiffQueryConduitAPIMethod::getResult(ConduitAPIRequest) called at [<phabricator>/src/applications/diffusion/conduit/DiffusionQueryConduitAPIMethod.php:135]
PHP message: #6 DiffusionQueryConduitAPIMethod::execute(ConduitAPIRequest) called at [<phabricator>/src/applications/conduit/method/ConduitAPIMethod.php:90]
PHP message: #7 ConduitAPIMethod::executeMethod(ConduitAPIRequest) called at [<phabricator>/src/applications/conduit/call/ConduitCall.php:134]
PHP message: #8 ConduitCall::executeMethod() called at [<phabricator>/src/applications/conduit/call/ConduitCall.php:84]
PHP message: #9 ConduitCall::execute() called at [<phabricator>/src/applications/diffusion/query/DiffusionQuery.php:81]
PHP message: #10 DiffusionQuery::callConduitWithDiffusionRequest(PhabricatorUser, DiffusionGitRequest, string, array) called at [<phabricator>/src/applications/diffusion/controller/DiffusionController.php:184]
PHP message: #11 DiffusionController::callConduitWithDiffusionRequest(string, array) called at [<phabricat
```

Test Plan: I'm just going to push this to make sure it fixes things, since I can't repro it locally.

Reviewers: btrahan

Subscribers: epriestley

Differential Revision: https://secure.phabricator.com/D12571

+26 -1
+26 -1
support/PhabricatorStartup.php
··· 425 425 $_POST = array_merge($_POST, $filtered); 426 426 break; 427 427 case INPUT_ENV; 428 - $_ENV = array_merge($_ENV, $filtered); 428 + $env = array_merge($_ENV, $filtered); 429 + $_ENV = self::filterEnvSuperglobal($env); 429 430 break; 430 431 } 431 432 } ··· 457 458 } 458 459 } 459 460 } 461 + 462 + 463 + /** 464 + * Adjust `$_ENV` before execution. 465 + * 466 + * Adjustments here primarily impact the environment as seen by subprocesses. 467 + * The environment is forwarded explicitly by @{class:ExecFuture}. 468 + * 469 + * @param map<string, wild> Input `$_ENV`. 470 + * @return map<string, string> Suitable `$_ENV`. 471 + * @task validation 472 + */ 473 + private static function filterEnvSuperglobal(array $env) { 474 + 475 + // In some configurations, we may get "argc" and "argv" set in $_ENV. 476 + // These are not real environmental variables, and "argv" may have an array 477 + // value which can not be forwarded to subprocesses. Remove these from the 478 + // environment if they are present. 479 + unset($env['argc']); 480 + unset($env['argv']); 481 + 482 + return $env; 483 + } 484 + 460 485 461 486 /** 462 487 * @task validation