1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-19 16:58:48 +02:00

Fix InvalidArgumentException on commit hook

Summary:
Fix a regression introduced here:

96ae4ba13a

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
This commit is contained in:
Valerio Bozzolan 2023-04-14 22:08:15 +02:00
parent 1b9da964e9
commit a5c93dea56

View file

@ -119,6 +119,7 @@ if ($is_svnrevprop) {
exit($err); exit($err);
} else if ($repository->isGit() || $repository->isHg()) { } else if ($repository->isGit() || $repository->isHg()) {
$username = getenv(DiffusionCommitHookEngine::ENV_USER); $username = getenv(DiffusionCommitHookEngine::ENV_USER);
if ($username !== false) {
if (!phutil_nonempty_string($username)) { if (!phutil_nonempty_string($username)) {
throw new Exception( throw new Exception(
pht( pht(
@ -126,6 +127,7 @@ if ($is_svnrevprop) {
'This will not work. See "No Direct Pushes" in the documentation '. 'This will not work. See "No Direct Pushes" in the documentation '.
'for more information.')); 'for more information.'));
} }
}
if ($repository->isHg()) { if ($repository->isHg()) {
// We respond to several different hooks in Mercurial. // We respond to several different hooks in Mercurial.
@ -181,18 +183,24 @@ $engine->setStdin($stdin);
$engine->setOriginalArgv(array_slice($argv, 2)); $engine->setOriginalArgv(array_slice($argv, 2));
$remote_address = getenv(DiffusionCommitHookEngine::ENV_REMOTE_ADDRESS); $remote_address = getenv(DiffusionCommitHookEngine::ENV_REMOTE_ADDRESS);
if (phutil_nonempty_string($remote_address)) { if ($remote_address !== false) {
if (phutil_nonempty_string($remote_address)) {
$engine->setRemoteAddress($remote_address); $engine->setRemoteAddress($remote_address);
}
} }
$remote_protocol = getenv(DiffusionCommitHookEngine::ENV_REMOTE_PROTOCOL); $remote_protocol = getenv(DiffusionCommitHookEngine::ENV_REMOTE_PROTOCOL);
if (phutil_nonempty_string($remote_protocol)) { if ($remote_protocol !== false) {
if (phutil_nonempty_string($remote_protocol)) {
$engine->setRemoteProtocol($remote_protocol); $engine->setRemoteProtocol($remote_protocol);
}
} }
$request_identifier = getenv(DiffusionCommitHookEngine::ENV_REQUEST); $request_identifier = getenv(DiffusionCommitHookEngine::ENV_REQUEST);
if (phutil_nonempty_string($request_identifier)) { if ($request_identifier !== false) {
if (phutil_nonempty_string($request_identifier)) {
$engine->setRequestIdentifier($request_identifier); $engine->setRequestIdentifier($request_identifier);
}
} }
try { try {