Skip to content

Commit f694aa8

Browse files
tristankretzernicolas-grekas
authored andcommitted
[HttpFoundation] Fix bad return type in IpUtils::checkIp4()
1 parent 387a6b0 commit f694aa8

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/Symfony/Component/HttpFoundation/IpUtils.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public static function checkIp4(?string $requestIp, string $ip)
8686
[$address, $netmask] = explode('/', $ip, 2);
8787

8888
if ('0' === $netmask) {
89-
return self::$checkedIps[$cacheKey] = filter_var($address, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV4);
89+
return self::$checkedIps[$cacheKey] = false !== filter_var($address, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV4);
9090
}
9191

9292
if ($netmask < 0 || $netmask > 32) {

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,21 @@ public function anonymizedIpData()
164164
['::123.234.235.236', '::123.234.235.0'], // deprecated IPv4-compatible IPv6 address
165165
];
166166
}
167+
168+
/**
169+
* @dataProvider getIp4SubnetMaskZeroData
170+
*/
171+
public function testIp4SubnetMaskZero($matches, $remoteAddr, $cidr)
172+
{
173+
$this->assertSame($matches, IpUtils::checkIp4($remoteAddr, $cidr));
174+
}
175+
176+
public function getIp4SubnetMaskZeroData()
177+
{
178+
return [
179+
[true, '1.2.3.4', '0.0.0.0/0'],
180+
[true, '1.2.3.4', '192.168.1.0/0'],
181+
[false, '1.2.3.4', '256.256.256/0'], // invalid CIDR notation
182+
];
183+
}
167184
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy