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
Unknown Object (File)
Mon, May 13, 22:34
Unknown Object (File)
Sun, May 12, 23:55
Unknown Object (File)
Sun, May 12, 12:26
Unknown Object (File)
Fri, May 10, 13:20
Unknown Object (File)
Wed, May 8, 23:44
Unknown Object (File)
Wed, May 8, 11:23
Unknown Object (File)
Wed, May 8, 11:23
Unknown Object (File)
Wed, May 8, 10:11

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
Lint
Lint Not Applicable
Unit
Tests Not Applicable

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!