From 41afb596e6f157f3163a0124e993d160a3a8447d Mon Sep 17 00:00:00 2001 From: Stevani Andolo Date: Wed, 7 Jun 2023 18:51:11 +0800 Subject: [PATCH] MDL-78215 core: support checking if 0.0.0.0 is in subnet --- lib/classes/files/curl_security_helper.php | 2 +- lib/moodlelib.php | 5 +++-- lib/upgrade.txt | 3 +++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/classes/files/curl_security_helper.php b/lib/classes/files/curl_security_helper.php index 276b7aa447a..26e07bab6ae 100644 --- a/lib/classes/files/curl_security_helper.php +++ b/lib/classes/files/curl_security_helper.php @@ -223,7 +223,7 @@ class curl_security_helper extends curl_security_helper_base { protected function address_explicitly_blocked($addr) { $blockedhosts = $this->get_blocked_hosts_by_category(); $iphostsblocked = array_merge($blockedhosts['ipv4'], $blockedhosts['ipv6']); - return address_in_subnet($addr, implode(',', $iphostsblocked)); + return address_in_subnet($addr, implode(',', $iphostsblocked), true); } /** diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 90cb8a0e0a6..f8fc91ef86e 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -8956,11 +8956,12 @@ function make_unique_id_code($extra = '') { * * @param string $addr The address you are checking * @param string $subnetstr The string of subnet addresses + * @param bool $checkallzeros The state to whether check for 0.0.0.0 * @return bool */ -function address_in_subnet($addr, $subnetstr) { +function address_in_subnet($addr, $subnetstr, $checkallzeros = false) { - if ($addr == '0.0.0.0') { + if ($addr == '0.0.0.0' && !$checkallzeros) { return false; } $subnets = explode(',', $subnetstr); diff --git a/lib/upgrade.txt b/lib/upgrade.txt index bd63cff63ea..2ebc2eebc0f 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -1,6 +1,9 @@ This files describes API changes in core libraries and APIs, information provided here is intended especially for developers. +=== 3.11.15 === +* Added a new parameter in address_in_subnet to give us the ability to check for 0.0.0.0 or not. + === 3.11.14 === * Added 'extrainfo' in the DB options config. Its extra information for the DB driver, e.g. SQL Server, has additional configuration according to its environment, which the administrator can specify to alter and