From 82d1abd4edd12431926008c9b27d8de06ac9a4a5 Mon Sep 17 00:00:00 2001 From: Andre Klapper Date: Tue, 25 Apr 2023 15:39:38 +0200 Subject: [PATCH] Fix PHP 8.1 "strlen(null)" exception in PhutilOpaqueEnvelope.php Summary: This change fixes a RuntimeException for passing null to strlen() when setting up the DB host parameter Closes T15260 Test Plan: I was able to run "./bin/config set mysql.host "localhost"" successfully Reviewers: O1 Blessed Committers, avivey Reviewed By: O1 Blessed Committers, avivey Subscribers: Ekubischta, goddenrich, Dylsss, speck, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T15260 Differential Revision: https://we.phorge.it/D25129 --- src/error/PhutilOpaqueEnvelope.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/error/PhutilOpaqueEnvelope.php b/src/error/PhutilOpaqueEnvelope.php index 1c9024ba..ef773fb1 100644 --- a/src/error/PhutilOpaqueEnvelope.php +++ b/src/error/PhutilOpaqueEnvelope.php @@ -60,11 +60,13 @@ final class PhutilOpaqueEnvelope extends Phobject { */ private function mask($string, $noise) { $result = ''; - for ($ii = 0; $ii < strlen($string); $ii++) { - $s = $string[$ii]; - $n = $noise[$ii % strlen($noise)]; + if (phutil_nonempty_string($string)) { + for ($ii = 0; $ii < strlen($string); $ii++) { + $s = $string[$ii]; + $n = $noise[$ii % strlen($noise)]; - $result .= chr(ord($s) ^ ord($n)); + $result .= chr(ord($s) ^ ord($n)); + } } return $result; }