From: Aaron Schulz Date: Wed, 15 Jan 2014 03:58:03 +0000 (-0800) Subject: Workaround ip2long limitation X-Git-Tag: 1.31.0-rc.0~17232 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_aide%28?a=commitdiff_plain;h=ed6abd6b0463f22997b2df4d51f3e0596c0f88a7;p=lhc%2Fweb%2Fwiklou.git Workaround ip2long limitation * This was resulting in bogus queries that did ipblock table scans bug: 60035 Change-Id: Id8f8846e002abcc0010c8706c664db86257786bf --- diff --git a/includes/utils/IP.php b/includes/utils/IP.php index 2686e1133c..871f71bcdc 100644 --- a/includes/utils/IP.php +++ b/includes/utils/IP.php @@ -489,6 +489,8 @@ class IP { if ( self::isIPv6( $ip ) ) { $n = self::toUnsigned6( $ip ); } else { + // Bug 60035: an IP with leading 0's fails in ip2long sometimes (e.g. *.08) + $ip = preg_replace( '/(?<=\.)0+(?=[1-9])/', '', $ip ); $n = ip2long( $ip ); if ( $n < 0 ) { $n += pow( 2, 32 ); diff --git a/tests/phpunit/includes/utils/IPTest.php b/tests/phpunit/includes/utils/IPTest.php index 24b077a3f5..1267268364 100644 --- a/tests/phpunit/includes/utils/IPTest.php +++ b/tests/phpunit/includes/utils/IPTest.php @@ -297,6 +297,8 @@ class IPTest extends MediaWikiTestCase { array( 16909060, '1.2.3.4' ), array( 2130706433, '127.0.0.1' ), array( '2147483648', '128.0.0.0' ), + array( 2130706440, '127.0.0.08' ), + array( 2130706441, '127.0.0.09' ), array( '3735931646', '222.173.202.254' ), array( pow( 2, 32 ) - 1, '255.255.255.255' ), array( false, 'IN.VA.LI.D' ),