File tree Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments