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

Commit e494f3c

Browse files
committed
Merge branch '2.5'
* 2.5: (23 commits) [HttpKernel] fixed some unit tests for 2.4 (signature now uses SHA256 instead of MD5) [HttpKernel] simplified code [HttpKernel] fixed internal fragment handling fixing yaml indentation Unexpexted ));" [WebProfiler] replaced the import/export feature from the web interface to a CLI tool Forced all fragment uris to be signed, even for ESI Add tests and more assertions [FrameworkBundle][Translator] Validate locales. [HttpFoundation] added some missing tests [HttpFoundation] Improve string values in test codes [Security] Add more tests for StringUtils::equals fix comment: not fourth but sixth argument fixing typo in a comment [FrameworkBundle] fixed CS [FrameworkBundle] PhpExtractor bugfix and improvements [Finder] Fix findertest readability [Filesystem] Add FTP stream wrapper context option to enable overwrite (override) fix parsing of Authorization header Test examples from Drupal SA-CORE-2014-003 ... Conflicts: src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/admin.html.twig src/Symfony/Component/Filesystem/Filesystem.php src/Symfony/Component/HttpKernel/Fragment/EsiFragmentRenderer.php
2 parents 8637c7d + 12cf916 commit e494f3c

File tree

2 files changed

+45
-11
lines changed

2 files changed

+45
-11
lines changed

Core/Tests/Util/StringUtilsTest.php

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,49 @@
1313

1414
use Symfony\Component\Security\Core\Util\StringUtils;
1515

16+
/**
17+
* Data from PHP.net's hash_equals tests
18+
*/
1619
class StringUtilsTest extends \PHPUnit_Framework_TestCase
1720
{
18-
public function testEquals()
21+
public function dataProviderTrue()
22+
{
23+
return array(
24+
array('same', 'same'),
25+
array('', ''),
26+
array(123, 123),
27+
array(null, ''),
28+
array(null, null),
29+
);
30+
}
31+
32+
public function dataProviderFalse()
33+
{
34+
return array(
35+
array('not1same', 'not2same'),
36+
array('short', 'longer'),
37+
array('longer', 'short'),
38+
array('', 'notempty'),
39+
array('notempty', ''),
40+
array(123, 'NaN'),
41+
array('NaN', 123),
42+
array(null, 123),
43+
);
44+
}
45+
46+
/**
47+
* @dataProvider dataProviderTrue
48+
*/
49+
public function testEqualsTrue($known, $user)
50+
{
51+
$this->assertTrue(StringUtils::equals($known, $user));
52+
}
53+
54+
/**
55+
* @dataProvider dataProviderFalse
56+
*/
57+
public function testEqualsFalse($known, $user)
1958
{
20-
$this->assertTrue(StringUtils::equals('password', 'password'));
21-
$this->assertFalse(StringUtils::equals('password', 'foo'));
59+
$this->assertFalse(StringUtils::equals($known, $user));
2260
}
2361
}

Core/Util/StringUtils.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,19 @@ private function __construct() {}
3535
*/
3636
public static function equals($knownString, $userInput)
3737
{
38-
// Prevent issues if string length is 0
39-
$knownString .= chr(0);
40-
$userInput .= chr(0);
41-
4238
$knownLen = strlen($knownString);
4339
$userLen = strlen($userInput);
4440

41+
// Extend the known string to avoid uninitialized string offsets
42+
$knownString .= $userInput;
43+
4544
// Set the result to the difference between the lengths
4645
$result = $knownLen - $userLen;
4746

4847
// Note that we ALWAYS iterate over the user-supplied length
4948
// This is to prevent leaking length information
5049
for ($i = 0; $i < $userLen; $i++) {
51-
// Using % here is a trick to prevent notices
52-
// It's safe, since if the lengths are different
53-
// $result is already non-0
54-
$result |= (ord($knownString[$i % $knownLen]) ^ ord($userInput[$i]));
50+
$result |= (ord($knownString[$i]) ^ ord($userInput[$i]));
5551
}
5652

5753
// They are only identical strings if $result is exactly 0...

0 commit comments

Comments
 (0)