Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions 12 src/Symfony/Component/Security/Core/Util/StringUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,19 @@ private function __construct() {}
*/
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

$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...
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.