Skip to content

Commit

Permalink
Add more guard tests in functions in snmp helper.
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-unwin committed Sep 30, 2024
1 parent 91e0e83 commit 96858f0
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions app/Helpers/snmp_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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';
Expand Down Expand 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';
Expand Down Expand 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);
Expand Down

0 comments on commit 96858f0

Please sign in to comment.