From ef73b12b580ee10bd901299419f4edac20f06c1a Mon Sep 17 00:00:00 2001 From: Andre Klapper Date: Fri, 22 Mar 2024 11:25:57 +0100 Subject: [PATCH] Fix "strpos(): Non-string needles will be interpreted as strings" in PhutilSortVector Summary: Code checking if the needle string `$value` is somewhere in the haystack `"\0"` makes no sense for a single byte (if it did, then `strcmp` instead of `strpos` should have been used) and the created exception output implies that it's supposed to check that a string does not contain NULL bytes. Thus switch the order of arguments passed to `strpos()` to be correct. ``` EXCEPTION: (RuntimeException) strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior at [/src/error/PhutilErrorHandler.php:261] #0 <#2> PhutilErrorHandler::handleError(integer, string, string, integer, array) called at [/src/error/PhutilErrorHandler.php:261] #1 <#2> strpos(string, integer) called at [/src/utils/PhutilSortVector.php:33] ``` Closes T15755 Test Plan: Read the surrounding code carefully. Reviewers: O1 Blessed Committers, valerio.bozzolan, speck Reviewed By: O1 Blessed Committers, valerio.bozzolan, speck Subscribers: tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T15755 Differential Revision: https://we.phorge.it/D25557 --- src/utils/PhutilSortVector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/PhutilSortVector.php b/src/utils/PhutilSortVector.php index 00146070..1bddd22e 100644 --- a/src/utils/PhutilSortVector.php +++ b/src/utils/PhutilSortVector.php @@ -30,7 +30,7 @@ final class PhutilSortVector } public function addString($value) { - if (strlen($value) && (strpos("\0", $value) !== false)) { + if (strlen($value) && (strpos($value, "\0") !== false)) { throw new Exception( pht( 'String components of a sort vector must not contain NULL bytes.'));