@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.

Fix InvalidArgumentException on commit hook

Summary:
Fix a regression introduced here:

96ae4ba13acbf0e2f8932e950a92af0495f034d7

I reproduced this exception executing "svn commit" on a hosted repository.

That crash happened because the PHP getenv() function can return false.
But, that is a very terrible value that blasts the non-string-empty check.

So, now the default getenv() value is skipped, without causing problems.

Closes T15253
Ref T15190

Test Plan: - I've run `svn commit` and I have not encountered any issue now

Reviewers: O1 Blessed Committers, avivey

Reviewed By: O1 Blessed Committers, avivey

Subscribers: speck, tobiaswiese, Matthew, Cigaryno

Maniphest Tasks: T15253, T15190

Differential Revision: https://we.phorge.it/D25122

+20 -12
+20 -12
scripts/repository/commit_hook.php
··· 119 119 exit($err); 120 120 } else if ($repository->isGit() || $repository->isHg()) { 121 121 $username = getenv(DiffusionCommitHookEngine::ENV_USER); 122 - if (!phutil_nonempty_string($username)) { 123 - throw new Exception( 124 - pht( 125 - 'No Direct Pushes: You are pushing directly to a hosted repository. '. 126 - 'This will not work. See "No Direct Pushes" in the documentation '. 127 - 'for more information.')); 122 + if ($username !== false) { 123 + if (!phutil_nonempty_string($username)) { 124 + throw new Exception( 125 + pht( 126 + 'No Direct Pushes: You are pushing directly to a hosted repository. '. 127 + 'This will not work. See "No Direct Pushes" in the documentation '. 128 + 'for more information.')); 129 + } 128 130 } 129 131 130 132 if ($repository->isHg()) { ··· 181 183 $engine->setOriginalArgv(array_slice($argv, 2)); 182 184 183 185 $remote_address = getenv(DiffusionCommitHookEngine::ENV_REMOTE_ADDRESS); 184 - if (phutil_nonempty_string($remote_address)) { 185 - $engine->setRemoteAddress($remote_address); 186 + if ($remote_address !== false) { 187 + if (phutil_nonempty_string($remote_address)) { 188 + $engine->setRemoteAddress($remote_address); 189 + } 186 190 } 187 191 188 192 $remote_protocol = getenv(DiffusionCommitHookEngine::ENV_REMOTE_PROTOCOL); 189 - if (phutil_nonempty_string($remote_protocol)) { 190 - $engine->setRemoteProtocol($remote_protocol); 193 + if ($remote_protocol !== false) { 194 + if (phutil_nonempty_string($remote_protocol)) { 195 + $engine->setRemoteProtocol($remote_protocol); 196 + } 191 197 } 192 198 193 199 $request_identifier = getenv(DiffusionCommitHookEngine::ENV_REQUEST); 194 - if (phutil_nonempty_string($request_identifier)) { 195 - $engine->setRequestIdentifier($request_identifier); 200 + if ($request_identifier !== false) { 201 + if (phutil_nonempty_string($request_identifier)) { 202 + $engine->setRequestIdentifier($request_identifier); 203 + } 196 204 } 197 205 198 206 try {