Page MenuHomePhorge

Fix PHP 8.1 "strlen(null)" exception on LDAP login without password
ClosedPublic

Authored by aklapper on Jul 26 2024, 14:46.
Tags
None
Referenced Files
F3403310: D25748.1744571893.diff
Sat, Apr 12, 19:18
F3387453: D25748.1744436940.diff
Fri, Apr 11, 05:49
F3383587: D25748.1744391399.diff
Thu, Apr 10, 17:09
F3377260: D25748.1744337764.diff
Thu, Apr 10, 02:16
F3376022: D25748.1744318350.diff
Wed, Apr 9, 20:52
F3369669: D25748.1744215971.diff
Tue, Apr 8, 16:26
F3369508: D25748.1744215172.diff
Tue, Apr 8, 16:12
F3369316: D25748.1744214176.diff
Tue, Apr 8, 15:56

Details

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.

Note: This patch also corrects two further strlen() occurrences with the same pattern.

ERROR 8192: strlen(): Passing null to parameter #1 ($string) of type string is deprecated at [/var/www/html/phorge/phorge/src/applications/auth/provider/PhabricatorLDAPAuthProvider.php:145]

Closes T15893

Test Plan

Create an LDAP user without setting their password; try to log into Phabricator with that user via the LDAP auth provider.

Diff Detail

Repository
rP Phorge
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Thaaaanks. I wonder why $has_password has a dedicated variable, and instead $has_username has not 🤔

Feel free to introduce $has_username if your moon isn't full right now 👍 both for readability and micro-optimization.

This revision is now accepted and ready to land.Jul 26 2024, 16:09

The $password variable is not a string anymore in the line after. I guess it's not much more expensive to check if the string $username is nonempty versus comparing to a boolean value