Yuvipanda has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/107044


Change subject: Fix for IP detection.
......................................................................

Fix for IP detection.

Better IP detector

Change-Id: I8447c8f2c55495c64848f94db5d89dd405ccd518
---
M includes/User.php
M includes/utils/IP.php
2 files changed, 5 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/44/107044/1

diff --git a/includes/User.php b/includes/User.php
index ca3f79b..e00a425 100644
--- a/includes/User.php
+++ b/includes/User.php
@@ -541,11 +541,9 @@
         * Does the string match an anonymous IPv4 address?
         *
         * This function exists for username validation, in order to reject
-        * usernames which are similar in form to IP addresses. Strings such
-        * as 300.300.300.300 will return true because it looks like an IP
-        * address, despite not being strictly valid.
+        * usernames which are similar in form to IP addresses.
         *
-        * We match "\d{1,3}\.\d{1,3}\.\d{1,3}\.xxx" as an anonymous IP
+        * We match 000-255\.000-255\.000-255\.xxx as an anonymous IP
         * address because the usemod software would "cloak" anonymous IP
         * addresses like this, if we allowed accounts like this to be created
         * new users could get the old edits of these anonymous users.
@@ -554,7 +552,8 @@
         * @return bool
         */
        public static function isIP( $name ) {
-               return preg_match( 
'/^\d{1,3}\.\d{1,3}\.\d{1,3}\.(?:xxx|\d{1,3})$/', $name ) || IP::isIPv6( $name 
);
+               # Matches if the IP range is actually between 0.0.0.0 and 
255.255.255.255
+               return 
preg_match('/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:xxx|25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/',$name
 || IP::isIPv6($name));
        }
 
        /**
diff --git a/includes/utils/IP.php b/includes/utils/IP.php
index 2686e11..723c8a2 100644
--- a/includes/utils/IP.php
+++ b/includes/utils/IP.php
@@ -24,7 +24,7 @@
 // Some regex definition to "play" with IP address and IP address blocks
 
 // An IPv4 address is made of 4 bytes from x00 to xFF which is d0 to d255
-define( 'RE_IP_BYTE', '(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|0?[0-9]?[0-9])' );
+define( 'RE_IP_BYTE', '(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)' );
 define( 'RE_IP_ADD', RE_IP_BYTE . '\.' . RE_IP_BYTE . '\.' . RE_IP_BYTE . '\.' 
. RE_IP_BYTE );
 // An IPv4 block is an IP address and a prefix (d1 to d32)
 define( 'RE_IP_PREFIX', '(3[0-2]|[12]?\d)' );

-- 
To view, visit https://gerrit.wikimedia.org/r/107044
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8447c8f2c55495c64848f94db5d89dd405ccd518
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Yuvipanda <yuvipa...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to