Skip to content

Commit

Permalink
Fixing #5420 - snmp->get() method failures due to trim
Browse files Browse the repository at this point in the history
PHP8.1.x, PHP-SNMP and snmp->get() errors due to improper use of trim() function
  • Loading branch information
TheWitness committed Jul 24, 2023
1 parent 14cb431 commit 1a2fb03
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Cacti CHANGELOG
-issue#5413: Rows Per Page - Not all options are available
-issue#5414: Plugins are unable to modify fields in the setting 'Change Device Settings'
-issue#5417: Cacti mailer log message misses 'bcc' addresses in log notification
-issue#5420: PHP8.1.x, PHP-SNMP and snmp->get() errors due to improper use of trim() function
-feature#5375: Add template for Fortinet firewall and Aruba Instant cluster
-feature#5393: Add template for SNMP printer
-feature#5418: Display device class before package import
Expand Down
9 changes: 8 additions & 1 deletion lib/snmp.php
Original file line number Diff line number Diff line change
Expand Up @@ -491,10 +491,16 @@ function cacti_snmp_session_get($session, $oid, $strip_alpha = false) {
if (is_array($oid) && cacti_sizeof($oid) == 0) {
cacti_log('Empty OID!', false);
return array();
} elseif (is_array($oid)) {
foreach($oid as $index => $o) {
$oid[$index] = trim($o);
}
} else {
$oid = trim($oid);
}

try {
$out = @$session->get(trim($oid));
$out = @$session->get($oid);
} catch (Exception $e) {
$out = false;
}
Expand All @@ -507,6 +513,7 @@ function cacti_snmp_session_get($session, $oid, $strip_alpha = false) {
if ($session->getErrno() == SNMP::ERRNO_TIMEOUT) {
cacti_log('WARNING: SNMP Error:\'Timeout (' . round($info['timeout']/1000,0) . " ms)', Device:'" . $info['hostname'] . "', OID:'$oid'", false, 'SNMP', POLLER_VERBOSITY_HIGH);
}

return false;
}

Expand Down

0 comments on commit 1a2fb03

Please sign in to comment.