From 96858f0f73938b88fef1f11296029a19b3e30208 Mon Sep 17 00:00:00 2001 From: Mark Unwin Date: Mon, 30 Sep 2024 10:14:03 +1000 Subject: [PATCH] Add more guard tests in functions in snmp helper. --- app/Helpers/snmp_helper.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/app/Helpers/snmp_helper.php b/app/Helpers/snmp_helper.php index eb669d21a..ed4b52cd7 100644 --- a/app/Helpers/snmp_helper.php +++ b/app/Helpers/snmp_helper.php @@ -282,11 +282,11 @@ function my_snmp_get($ip, $credentials, $oid) break; default: - return false; + return ''; break; } if (empty($string) && $string !== '0') { - return false; + return ''; } if ($string === '""') { $string = ''; @@ -351,11 +351,11 @@ function my_snmp_walk($ip, $credentials, $oid) break; default: - return false; + return array(); break; } if (! is_array($array)) { - return false; + return array(); } foreach ($array as $key => $value) { $value = $value; @@ -423,11 +423,11 @@ function my_snmp_real_walk($ip, $credentials, $oid) break; default: - return false; + return array(); break; } if (! is_array($array)) { - return false; + return array(); } foreach ($array as $key => $value) { $value = $value; @@ -2166,6 +2166,9 @@ function format_mac($mac_address) */ function ip_enabled($ip_enabled) { + if (empty($ip_enabled)) { + return 'up'; + } switch ($ip_enabled) { case '1': $ip_enabled = 'up'; @@ -2212,6 +2215,9 @@ function ip_enabled($ip_enabled) */ function if_admin_status($ifadminstatus) { + if (empty($ifadminstatus)) { + return 'up'; + } switch ($ifadminstatus) { case '1': $ifadminstatus = 'up'; @@ -2242,6 +2248,9 @@ function if_admin_status($ifadminstatus) */ function interface_type($int_type) { + if (empty($int_type)) { + return ''; + } $temp = (string) intval($int_type); if ($int_type !== $temp) { $int_type = substr($int_type, strpos($int_type, '(')+1);