diff options
author | Yosmany Garcia <yosmanyga@gmail.com> | 2014-08-05 20:01:06 -0400 |
---|---|---|
committer | Yosmany Garcia <yosmanyga@gmail.com> | 2014-08-14 12:15:45 +0000 |
commit | a982db769f3a9e1d1c6f4f8740f69454231270b0 (patch) | |
tree | 885626655a43f6b13f6d5fff8b6e5f0a46721861 | |
parent | 5a4f252c4470b0d4e2fc23bb06752ae1559b97a3 (diff) | |
download | symfony-security-a982db769f3a9e1d1c6f4f8740f69454231270b0.zip symfony-security-a982db769f3a9e1d1c6f4f8740f69454231270b0.tar.gz symfony-security-a982db769f3a9e1d1c6f4f8740f69454231270b0.tar.bz2 |
Made optimization deprecating modulus operator
-rw-r--r-- | Core/Util/StringUtils.php | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/Core/Util/StringUtils.php b/Core/Util/StringUtils.php index d47bd4b..eaeed84 100644 --- a/Core/Util/StringUtils.php +++ b/Core/Util/StringUtils.php @@ -35,23 +35,19 @@ class StringUtils */ public static function equals($knownString, $userInput) { - // Prevent issues if string length is 0 - $knownString .= chr(0); - $userInput .= chr(0); - $knownLen = strlen($knownString); $userLen = strlen($userInput); + // Extend know string to avoid uninitialized string offsets + $knownString .= $userInput; + // Set the result to the difference between the lengths $result = $knownLen - $userLen; // Note that we ALWAYS iterate over the user-supplied length // This is to prevent leaking length information for ($i = 0; $i < $userLen; $i++) { - // Using % here is a trick to prevent notices - // It's safe, since if the lengths are different - // $result is already non-0 - $result |= (ord($knownString[$i % $knownLen]) ^ ord($userInput[$i])); + $result |= (ord($knownString[$i]) ^ ord($userInput[$i])); } // They are only identical strings if $result is exactly 0... |