Page MenuHomePhorge

Fix preamble-support
ClosedPublic

Authored by avivey on Apr 7 2023, 10:25.
Tags
None
Referenced Files
F2157049: D25114.diff
Wed, Apr 24, 06:35
Unknown Object (File)
Sun, Apr 7, 10:22
Unknown Object (File)
Tue, Apr 2, 23:58
Unknown Object (File)
Mon, Apr 1, 01:10
Unknown Object (File)
Sun, Mar 31, 03:09
Unknown Object (File)
Sat, Mar 30, 22:34
Unknown Object (File)
Sat, Mar 30, 11:48
Unknown Object (File)
Wed, Mar 27, 18:04

Details

Summary

Phutil is not yet loaded during preamble, so we can't use it.

This change fixes a regression introduced here, fixing PHP 8.1 support:

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

Ref T15064

Test Plan

Included test script.

Diff Detail

Repository
rP Phorge
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

avivey requested review of this revision.Apr 7 2023, 10:25
support/startup/preamble-utils.php
24

I suggest a strict check there.

I also strongly would like to push this that is what we exactly want, so, exclude NULL, have a string, and have it non-empty:

if(is_string($forwarded_for) && $forwarded_for !== '') {
support/startup/preamble-utils.php
24

Ouch note that both the patch and my suggestions are incorrect.

The correct way is the total reverse, so:

if ($forwarded_for === null || !strlen($forwarded_for)) {

Or, what I would like to use:

if(!is_string($forwarded_for) || $forwarded_for === '') {
This revision now requires changes to proceed.Apr 7 2023, 13:39

Hi @avivey thanks for this fix in my regression. Feel free to update this to just negate the if and make it correct, or here there is a quick fix ready to be accepted:

D25119: Fix regression in preamble

(I've done that just in order to be nice and don't bother you with additional fatigue for my regression. So, if you have time just continue here, or move to D25119)

Since the bug you found was major, and my tests didn't catch it, I'm going to do another round of more in-depth testing for this...

support/startup/preamble-utils.php
24

To reduce count of double-negatives, let's add phutil_is_empty_string() function.

support/startup/preamble-utils.php
24

actually, it might end up more confusing with NULL inputs.

add tests and keep simplest code

Added a test-script to check all possible inputs. It's not run automatically, because this isn't part of the main code.

Anyway, turns out that $forwarded_for in line 23 is never null, because "isset() will return false when checking a variable that has been assigned to null." (https://www.php.net/manual/en/function.isset); so strlen is fine here.

Thank you for this fix and for the tests

I still recommend this:

if(!is_string($forwarded_for) || $forwarded_for === '') {

In order to exclude non-strings, non empty strings, and with O(1) complexity instead of O(N) or something depending on the length of the string, so that we minimize CPU cycles and Greta Thunberg goes like "wooooow Phorge"

support/startup/preamble-utils.php
19

Yeah the NULL check is already done.

This revision is now accepted and ready to land.Apr 9 2023, 18:32
This revision was automatically updated to reflect the committed changes.