X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FIP.php;h=0943606e0432d8b51fedcee75d0c7f4020327c69;hb=af94bc9c69db033c7308192b42a47a4f27e25878;hp=72b9a52c8123d863bdbe44161c9760af778b496e;hpb=1f0fcc0f39211375f03e2e6e87fd5be179eff231;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/IP.php b/includes/IP.php index 72b9a52c81..0943606e04 100644 --- a/includes/IP.php +++ b/includes/IP.php @@ -33,7 +33,7 @@ define( 'RE_IP_BLOCK', RE_IP_ADD . '\/' . RE_IP_PREFIX ); // An IPv6 address is made up of 8 words (each x0000 to xFFFF). // However, the "::" abbreviation can be used on consecutive x0000 words. define( 'RE_IPV6_WORD', '([0-9A-Fa-f]{1,4})' ); -define( 'RE_IPV6_PREFIX', '(12[0-8]|1[01][0-9]|[1-9]?\d)'); +define( 'RE_IPV6_PREFIX', '(12[0-8]|1[01][0-9]|[1-9]?\d)' ); define( 'RE_IPV6_ADD', '(?:' . // starts with "::" (including "::") ':(?::|(?::' . RE_IPV6_WORD . '){1,7})' . @@ -392,11 +392,11 @@ class IP { static $privateRanges = false; if ( !$privateRanges ) { $privateRanges = array( - array( '10.0.0.0', '10.255.255.255' ), # RFC 1918 (private) - array( '172.16.0.0', '172.31.255.255' ), # " - array( '192.168.0.0', '192.168.255.255' ), # " - array( '0.0.0.0', '0.255.255.255' ), # this network - array( '127.0.0.0', '127.255.255.255' ), # loopback + array( '10.0.0.0', '10.255.255.255' ), # RFC 1918 (private) + array( '172.16.0.0', '172.31.255.255' ), # RFC 1918 (private) + array( '192.168.0.0', '192.168.255.255' ), # RFC 1918 (private) + array( '0.0.0.0', '0.255.255.255' ), # this network + array( '127.0.0.0', '127.255.255.255' ), # loopback ); } @@ -492,6 +492,11 @@ class IP { $n = ip2long( $ip ); if ( $n < 0 ) { $n += pow( 2, 32 ); + # On 32-bit platforms (and on Windows), 2^32 does not fit into an int, + # so $n becomes a float. We convert it to string instead. + if ( is_float ( $n ) ) { + $n = (string) $n; + } } } return $n; @@ -526,7 +531,7 @@ class IP { if ( $bits == 0 ) { $network = 0; } else { - $network &= ~( ( 1 << ( 32 - $bits ) ) - 1); + $network &= ~( ( 1 << ( 32 - $bits ) ) - 1 ); } # Convert to unsigned if ( $network < 0 ) {