1
0
mirror of https://github.com/moodle/moodle.git synced 2025-04-23 09:23:09 +02:00

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.

This commit is contained in:
tjhunt 2008-10-24 02:53:51 +00:00
parent 9488eba1f0
commit 6ff2be37f5
2 changed files with 4 additions and 1 deletions

@ -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);

@ -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'));
}
/**