Page MenuHomePhorge

PHP 8.1: fixes for strlen() not accepting NULL anymore, part 3
AbandonedPublic

Authored by valerio.bozzolan on Apr 1 2023, 09:55.
Referenced Files
Unknown Object (File)
Sun, Apr 28, 05:27
Unknown Object (File)
Mon, Apr 22, 22:15
Unknown Object (File)
Mon, Apr 22, 21:45
Unknown Object (File)
Mon, Apr 22, 21:45
Unknown Object (File)
Mon, Apr 22, 19:09
Unknown Object (File)
Mon, Apr 22, 18:45
Unknown Object (File)
Sun, Apr 14, 13:34
Unknown Object (File)
Sat, Apr 13, 10:34

Details

Summary

This is a fix for PHP 8.1 deprecation of strlen(NULL), for these Phorge components:

  • src/view
  • src/infrastructure (partial, needs more patches)

The strlen() was used in Phabricator to check if a generic value was a non-empty string.
For this reason, Phorge adopts phutil_nonempty_string() that checks that.

Note: this may highlight other absurd input values that might be worth correcting
instead of just ignoring. If your phutil_nonempty_string() throws an exception, just
report it to Phorge to evaluate and fix together that specific corner case.

Ref T15190
Ref T15064

Test Plan
  • check with big eyes that there are no obvious typos

Diff Detail

Repository
rP Phorge
Branch
massive-php-escape-part-3
Lint
Lint Passed
SeverityLocationCodeMessage
Advicesrc/infrastructure/export/field/PhabricatorOptionExportField.php:19XHP16TODO Comment
Unit
Tests Passed
Build Status
Buildable 215
Build 215: arc lint + arc unit

Event Timeline

As usual, the risk of this change is that exceptions may occur due to
really weird stuff coming in as input. In any case, if it happens,
it must be evaluated on a case-by-case basis, because in this case,
the previously present code (strlen) didn't make sense anyway either.

valerio.bozzolan retitled this revision from PHP 8.2: fixes for strlen() not accepting NULL anymore, part 3 to PHP 8.1: fixes for strlen() not accepting NULL anymore, part 3.Apr 1 2023, 13:08
valerio.bozzolan edited the summary of this revision. (Show Details)

fix AphrontFileResponse#setDownload() that had weird corner-cases

src/aphront/response/AphrontFileResponse.php
22 ↗(On Diff #449)

That above check was introduced by this commit:

rP96ae4ba13acb: PHP 8.1: fixes for strlen() not accepting NULL anymore, part 2

But it's too much strict. I have double-checked and this deserves more inline documentation. See on the right.

I just added some comments, and a strong default.

47 ↗(On Diff #449)

Also this method ↓ deserved an inline comment to show that it can return mixed stuff.

140 ↗(On Diff #449)
IMPORTANT: this cannot be used as-is, since getDownload() returns mixed stuff by design it seems.
valerio.bozzolan added inline comments.
src/infrastructure/log/PhabricatorSSHLog.php
38

This replacement has sense since everything from getenv() should be a string and we should report otherwise.

src/infrastructure/management/PhabricatorManagementWorkflow.php
17

This check has sense since then we use strtotime($time) so we really want a string, and we should report alien stuff.

src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php
2452

This check has sense since then we want to count length in bytes, so a string is necessary.

src/infrastructure/ssh/PhabricatorSSHWorkflow.php
104

This check has sense since we want a string and we want to report alien values from getenv().