Skip to content
This repository was archived by the owner on May 31, 2024. It is now read-only.

Commit 6a162c7

Browse files
sarciszewskifabpot
authored andcommitted
Update StringUtils.php
1 parent 551d5b0 commit 6a162c7

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

Core/Util/StringUtils.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ public static function equals($knownString, $userInput)
4545
return hash_equals($knownString, $userInput);
4646
}
4747

48-
$knownLen = strlen($knownString);
49-
$userLen = strlen($userInput);
48+
$knownLen = self::safeStrlen($knownString);
49+
$userLen = self::safeStrlen($userInput);
5050

5151
// Extend the known string to avoid uninitialized string offsets
5252
$knownString .= $userInput;
@@ -63,4 +63,18 @@ public static function equals($knownString, $userInput)
6363
// They are only identical strings if $result is exactly 0...
6464
return 0 === $result;
6565
}
66+
67+
/**
68+
* Return the number of bytes in a string
69+
*
70+
* @param string $string The string whose length we wish to obtain
71+
* @return int
72+
*/
73+
public static function safeStrlen($string)
74+
{
75+
if (function_exists('mb_strlen')) {
76+
return mb_strlen($string, '8bit');
77+
}
78+
return strlen($string);
79+
}
6680
}

0 commit comments

Comments
 (0)