bug #14690 [HttpFoundation] IpUtils::checkIp4() should allow /0 networks (zerkms)

This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes #14690).

Discussion
----------

[HttpFoundation] IpUtils::checkIp4() should allow `/0` networks

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | yes
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #14674
| License       | MIT

Technically it's a breaking change, since the result of the

    IpUtils::checkIp4('1.2.3.4', '0.0.0.0/0')

call was `false` now `true`.

Practically - no one should ever relied on this since it's simply wrong

Commits
-------

921ecff [HttpFoundation] IpUtils::checkIp4() should allow  networks
This commit is contained in:
Fabien Potencier 2015-05-20 09:39:40 +02:00
commit ea6e3d5109
2 changed files with 7 additions and 0 deletions

View File

@ -62,6 +62,10 @@ class IpUtils
public static function checkIp4($requestIp, $ip)
{
if (false !== strpos($ip, '/')) {
if ('0.0.0.0/0' === $ip) {
return true;
}
list($address, $netmask) = explode('/', $ip, 2);
if ($netmask < 1 || $netmask > 32) {

View File

@ -34,6 +34,9 @@ class IpUtilsTest extends \PHPUnit_Framework_TestCase
array(true, '192.168.1.1', array('1.2.3.4/1', '192.168.1.0/24')),
array(true, '192.168.1.1', array('192.168.1.0/24', '1.2.3.4/1')),
array(false, '192.168.1.1', array('1.2.3.4/1', '4.3.2.1/1')),
array(true, '1.2.3.4', '0.0.0.0/0'),
array(false, '1.2.3.4', '256.256.256/0'),
array(false, '1.2.3.4', '192.168.1.0/0'),
);
}