From: tjhunt Date: Fri, 24 Oct 2008 02:53:51 +0000 (+0000) Subject: moodlelib iprange checks: MDL-16986 If the user makes a mistake and types something... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=6ff2be37f55277d17f48142b47097b151778458e;p=moodle.git moodlelib iprange checks: MDL-16986 If the user makes a mistake and types something like 172.16.1.143/148, with something greater than 32 after the slash, treat it as /32. --- diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 21369aa81c..5a8a1d8c85 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -7237,6 +7237,8 @@ function make_unique_id_code($extra='') { * Code for type 1 modified from user posted comments by mediator at * {@link http://au.php.net/manual/en/function.ip2long.php} * + * TODO one day we will have to make this work with IP6. + * * @param string $addr The address you are checking * @param string $subnetstr The string of subnet addresses * @return bool @@ -7251,7 +7253,7 @@ function address_in_subnet($addr, $subnetstr) { $subnet = trim($subnet); if (strpos($subnet, '/') !== false) { /// type 1 list($ip, $mask) = explode('/', $subnet); - if ($mask === '') { + if ($mask === '' || $mask > 32) { $mask = 32; } $mask = 0xffffffff << (32 - $mask); diff --git a/lib/simpletest/testmoodlelib.php b/lib/simpletest/testmoodlelib.php index 26e755e2ef..f2947eb3b3 100644 --- a/lib/simpletest/testmoodlelib.php +++ b/lib/simpletest/testmoodlelib.php @@ -102,6 +102,7 @@ class moodlelib_test extends MoodleUnitTestCase { $this->assertFalse(address_in_subnet(' 2.1.2.3 ', ' 123.121.234.1 , 1.1.1.1/16,2.2.,3.3.3.3-6 ')); $this->assertFalse(address_in_subnet(' 2.3.234.1 ', ' 123.121.234.1 , 1.1.1.1/16,2.2.,3.3.3.3-6 ')); $this->assertFalse(address_in_subnet(' 3.3.3.7 ', ' 123.121.234.1 , 1.1.1.1/16,2.2.,3.3.3.3-6 ')); + $this->assertFalse(address_in_subnet('172.16.1.142', '172.16.1.143/148')); } /**