diff --git a/src/Symfony/Component/HttpFoundation/RequestMatcher.php b/src/Symfony/Component/HttpFoundation/RequestMatcher.php index 8cdce96fc9af..917be228d134 100644 --- a/src/Symfony/Component/HttpFoundation/RequestMatcher.php +++ b/src/Symfony/Component/HttpFoundation/RequestMatcher.php @@ -121,49 +121,49 @@ public function matches(Request $request) return false; } - if (null !== $this->ip && !$this->checkIp($request->getClientIp())) { + if (null !== $this->ip && !$this->checkIp($request->getClientIp(), $this->ip)) { return false; } return true; } - protected function checkIp($ip) + protected function checkIp($requestIp, $ip) { // IPv6 address - if (false !== strpos($ip, ':')) { - return $this->checkIp6($ip); + if (false !== strpos($requestIp, ':')) { + return $this->checkIp6($requestIp, $ip); } else { - return $this->checkIp4($ip); + return $this->checkIp4($requestIp, $ip); } } - protected function checkIp4($ip) + protected function checkIp4($requestIp, $ip) { - if (false !== strpos($this->ip, '/')) { - list($address, $netmask) = explode('/', $this->ip); + if (false !== strpos($ip, '/')) { + list($address, $netmask) = explode('/', $ip); if ($netmask < 1 || $netmask > 32) { return false; } } else { - $address = $this->ip; + $address = $ip; $netmask = 32; } - return 0 === substr_compare(sprintf('%032b', ip2long($ip)), sprintf('%032b', ip2long($address)), 0, $netmask); + return 0 === substr_compare(sprintf('%032b', ip2long($requestIp)), sprintf('%032b', ip2long($address)), 0, $netmask); } /** * @author David Soria Parra * @see https://github.com/dsp/v6tools */ - protected function checkIp6($ip) + protected function checkIp6($requestIp, $ip) { - list($address, $netmask) = explode('/', $this->ip); + list($address, $netmask) = explode('/', $ip); $bytes_addr = unpack("n*", inet_pton($address)); - $bytes_test = unpack("n*", inet_pton($ip)); + $bytes_test = unpack("n*", inet_pton($requestIp)); for ($i = 1, $ceil = ceil($netmask / 16); $i <= $ceil; $i++) { $left = $netmask - 16 * ($i-1);