X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=vendor%2Fsymfony%2Fhttp-foundation%2FIpUtils.php;h=a1bfa90885dcfb9204f220aab5a57b1fcfff21b1;hb=4e1bfbf98b844da83b18aca92ef00f11a4735806;hp=eba603b15df016d357973e4631863b73831b3ab9;hpb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;p=yaffs-website diff --git a/vendor/symfony/http-foundation/IpUtils.php b/vendor/symfony/http-foundation/IpUtils.php index eba603b15..a1bfa9088 100644 --- a/vendor/symfony/http-foundation/IpUtils.php +++ b/vendor/symfony/http-foundation/IpUtils.php @@ -37,7 +37,7 @@ class IpUtils */ public static function checkIp($requestIp, $ips) { - if (!is_array($ips)) { + if (!\is_array($ips)) { $ips = array($ips); } @@ -75,7 +75,7 @@ class IpUtils if (false !== strpos($ip, '/')) { list($address, $netmask) = explode('/', $ip, 2); - if ($netmask === '0') { + if ('0' === $netmask) { return self::$checkedIps[$cacheKey] = filter_var($address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4); } @@ -87,6 +87,10 @@ class IpUtils $netmask = 32; } + if (false === ip2long($address)) { + return self::$checkedIps[$cacheKey] = false; + } + return self::$checkedIps[$cacheKey] = 0 === substr_compare(sprintf('%032b', ip2long($requestIp)), sprintf('%032b', ip2long($address)), 0, $netmask); } @@ -112,13 +116,17 @@ class IpUtils return self::$checkedIps[$cacheKey]; } - if (!((extension_loaded('sockets') && defined('AF_INET6')) || @inet_pton('::1'))) { + if (!((\extension_loaded('sockets') && \defined('AF_INET6')) || @inet_pton('::1'))) { throw new \RuntimeException('Unable to check Ipv6. Check that PHP was not compiled with option "disable-ipv6".'); } if (false !== strpos($ip, '/')) { list($address, $netmask) = explode('/', $ip, 2); + if ('0' === $netmask) { + return (bool) unpack('n*', @inet_pton($address)); + } + if ($netmask < 1 || $netmask > 128) { return self::$checkedIps[$cacheKey] = false; }