Page MenuHomePhorge

Fix PHP 8.1 "strlen(null)" exception when Diffusion repository has no tags
ClosedPublic

Authored by aklapper on Jun 12 2023, 00:07.
Tags
None
Referenced Files
F2949265: D25285.1738611310.diff
Sun, Feb 2, 19:35
F2945886: D25285.1738370481.diff
Fri, Jan 31, 00:41
F2940192: D25285.1738041341.diff
Mon, Jan 27, 05:15
F2940191: D25285.1738041341.diff
Mon, Jan 27, 05:15
F2940056: D25285.1738037735.diff
Mon, Jan 27, 04:15
F2935150: D25285.1737825888.diff
Fri, Jan 24, 17:24
F2932267: D25285.1737730190.diff
Thu, Jan 23, 14:49
F2931483: D25285.1737710328.diff
Thu, Jan 23, 09:18

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.

EXCEPTION: (RuntimeException) strlen(): Passing null to parameter #1 ($string) of type string is deprecated at [<arcanist>/src/error/PhutilErrorHandler.php:261]
arcanist(head=diffusionEmptyRepoPatternSearch, ref.master=97e163187418, ref.diffusionEmptyRepoPatternSearch=97e163187418), phorge(head=master, ref.master=108cbcd09bd3)
  #0 <#2> PhutilErrorHandler::handleError(integer, string, string, integer) called at [<phorge>/src/applications/diffusion/controller/DiffusionTagListController.php:28]

Closes T15461

Test Plan

After applying this line, get the expected CommandException: Command failed with error #128! due to fatal: detected dubious ownership in repository at '/var/repo/1' (plus a RuntimeException: file_exists(): Passing null to parameter #1 ($filename) of type string is deprecated as a bonus), instead of the previous RuntimeException about strlen().

Diff Detail

Repository
rP Phorge
Branch
diffusionNoTags (branched from master)
Lint
Lint Passed
Unit
Tests Passed
Build Status
Buildable 537
Build 537: arc lint + arc unit

Event Timeline

speck added inline comments.
src/applications/diffusion/controller/DiffusionTagListController.php
28

The symbolic commit might not (always?) be a string here. Could you confirm that it is, or switch to a null check?

This revision is now accepted and ready to land.Jun 12 2023, 01:26
src/applications/diffusion/controller/DiffusionTagListController.php
28

https://we.phorge.it/source/phorge/browse/master/src/applications/diffusion/request/DiffusionRequest.php$275 states that getSymbolicCommit() is supposed to return string or null.

https://we.phorge.it/source/phorge/browse/master/src/applications/diffusion/request/DiffusionRequest.php$220 sets $this->symbolicCommit = idx($data, 'commit').

If this change led to an explosion than we'd know that the docs need fixing.

Still accepted~

src/applications/diffusion/controller/DiffusionTagListController.php
28

Thanks!