From 93ffe9c2009039da6f6f8bfb9e573c833b02188c Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Tue, 13 Mar 2007 19:25:49 +0000 Subject: [PATCH] *More robust IPv6 validation (exclude ambiguous IPs) --- includes/IP.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/includes/IP.php b/includes/IP.php index 883c3ef1a9..80efd1c762 100644 --- a/includes/IP.php +++ b/includes/IP.php @@ -36,11 +36,13 @@ class IP { */ public static function isIPAddress( $ip ) { if ( !$ip ) return false; - return preg_match( '/^' . IP_ADDRESS_STRING . '$/', $ip); + // IPv6 IPs with two "::" strings are ambiguous and this invalid + return preg_match( '/^' . IP_ADDRESS_STRING . '$/', $ip) && ( substr_count($ip, '::') < 2 ); } public static function isIPv6( $ip ) { - return preg_match( '/^' . RE_IPV6_ADD . '(\/' . RE_IPV6_PREFIX . '|)$/', $ip); + // IPv6 IPs with two "::" strings are ambiguous and this invalid + return preg_match( '/^' . RE_IPV6_ADD . '(\/' . RE_IPV6_PREFIX . '|)$/', $ip) && ( substr_count($ip, '::') < 2); } public static function isIPv4( $ip ) { -- 2.20.1