Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

moodlelib iprange checks: MDL-16986 If the user makes a mistake and t…

…ypes something like 172.16.1.143/148, with something greater than 32 after the slash, treat it as /32.
  • Loading branch information...
commit 4ca712272c2ad1a73f2b83c907c04bd778a691c2 1 parent 2631a4f
tjhunt authored
Showing with 4 additions and 3 deletions.
  1. +3 −1 lib/moodlelib.php
  2. +1 −2  lib/simpletest/testmoodlelib.php
View
4 lib/moodlelib.php
@@ -6004,6 +6004,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
@@ -6018,7 +6020,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);
View
3  lib/simpletest/testmoodlelib.php
@@ -54,8 +54,7 @@ function test_address_in_subnet() {
$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'));
}
-
}
-
?>
Please sign in to comment.
Something went wrong with that request. Please try again.