Skip to content

Commit cee9592

Browse files
committed
[HttpFoundation] Fixes IpUtils::checkIp4 on /0 subnets
| Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #16055 | License | MIT | Doc PR | Not needed
1 parent ad2e85e commit cee9592

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

src/Symfony/Component/HttpFoundation/IpUtils.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ public static function checkIp($requestIp, $ips)
6262
public static function checkIp4($requestIp, $ip)
6363
{
6464
if (false !== strpos($ip, '/')) {
65-
if ('0.0.0.0/0' === $ip) {
65+
list($address, $netmask) = explode('/', $ip, 2);
66+
67+
if ("0" === $netmask) {
6668
return true;
6769
}
6870

69-
list($address, $netmask) = explode('/', $ip, 2);
70-
7171
if ($netmask < 1 || $netmask > 32) {
7272
return false;
7373
}

src/Symfony/Component/HttpFoundation/Tests/IpUtilsTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ public function testIpv4Provider()
3535
array(true, '192.168.1.1', array('192.168.1.0/24', '1.2.3.4/1')),
3636
array(false, '192.168.1.1', array('1.2.3.4/1', '4.3.2.1/1')),
3737
array(true, '1.2.3.4', '0.0.0.0/0'),
38-
array(false, '1.2.3.4', '256.256.256/0'),
39-
array(false, '1.2.3.4', '192.168.1.0/0'),
38+
array(true, '1.2.3.4', '192.168.1.0/0'),
4039
);
4140
}
4241

0 commit comments

Comments
 (0)