From e5b47be78ff88396288af1c41d8d7a96769fff63 Mon Sep 17 00:00:00 2001 From: Daniel Caujolle-Bert Date: Mon, 31 Aug 2020 20:35:38 +0200 Subject: [PATCH] Take care of value returned by array_search(). Fix the offset while traversing the array, and return null if the offset is out of bounds. --- include/functions.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/include/functions.php b/include/functions.php index 4595521..8f76a90 100644 --- a/include/functions.php +++ b/include/functions.php @@ -168,15 +168,21 @@ function getDMRId ($mmdvmconfigs) { function getConfigItem($section, $key, $configs) { // retrieves the corresponding config-entry within a [section] - $sectionpos = array_search("[" . $section . "]", $configs) + 1; - $len = count($configs); - while(startsWith($configs[$sectionpos],$key."=") === false && $sectionpos <= ($len) ) { - if (startsWith($configs[$sectionpos],"[")) { - return null; - } + $sectionpos = arraye_search("[" . $section . "]", $configs); + if ($sectionpos !== FALSE) { $sectionpos++; + $len = count($configs); + while(($sectionpos < $len) && (startsWith($configs[$sectionpos],$key."=") === false) ) { + if (startsWith($configs[$sectionpos],"[")) { + return null; + } + $sectionpos++; + } + if ($sectionpos < $len) { + return substr($configs[$sectionpos], strlen($key) + 1); + } } - return substr($configs[$sectionpos], strlen($key) + 1); + return null; } function getEnabled ($mode, $mmdvmconfigs) {