From 8a1cfff1e8ab866b7fe77e4d29b7a1a2cb179314 Mon Sep 17 00:00:00 2001 From: Andre Klapper Date: Fri, 19 May 2023 16:59:07 +0200 Subject: [PATCH] Fix PHP 8.1 "strlen(null)" and "explode()" exceptions which block rendering Administrator Account Creation page Summary: `strlen()` was used in Phabricator to check if a generic value is a non-empty string. This behavior is deprecated since PHP 8.1. Phorge adopts `phutil_nonempty_string()` as a replacement. Note: this may highlight other absurd input values that might be worth correcting instead of just ignoring. If phutil_nonempty_string() throws an exception in your instance, report it to Phorge to evaluate and fix that specific corner case. Similarly, `explode(string $separator, string $string, int $limit)` does not accept passing null instead of an actual string as input parameter either anymore. Closes T15284 Test Plan: Applied these two changes. Afterwards, admin user account was created and Phorge homepage rendered in web browser on a fresh installation. Reviewers: O1 Blessed Committers, valerio.bozzolan Reviewed By: O1 Blessed Committers, valerio.bozzolan Subscribers: speck, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T15284 Differential Revision: https://we.phorge.it/D25175 --- src/applications/auth/constants/PhabricatorCookies.php | 2 +- .../people/cache/PhabricatorUserProfileImageCacheType.php | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/applications/auth/constants/PhabricatorCookies.php b/src/applications/auth/constants/PhabricatorCookies.php index 9675d21d42..9dc9d823b2 100644 --- a/src/applications/auth/constants/PhabricatorCookies.php +++ b/src/applications/auth/constants/PhabricatorCookies.php @@ -164,7 +164,7 @@ final class PhabricatorCookies extends Phobject { // Old cookies look like: /uri // New cookies look like: timestamp,/uri - if (!strlen($cookie)) { + if (!phutil_nonempty_string($cookie)) { return null; } diff --git a/src/applications/people/cache/PhabricatorUserProfileImageCacheType.php b/src/applications/people/cache/PhabricatorUserProfileImageCacheType.php index 8babff859f..195d880fff 100644 --- a/src/applications/people/cache/PhabricatorUserProfileImageCacheType.php +++ b/src/applications/people/cache/PhabricatorUserProfileImageCacheType.php @@ -91,6 +91,9 @@ final class PhabricatorUserProfileImageCacheType } public function isRawCacheDataValid(PhabricatorUser $user, $key, $data) { + if ($data === null) { + return false; + } $parts = explode(',', $data, 2); $version = reset($parts); return ($version === $this->getCacheVersion($user));