Skip to content

Commit 0ba3429

Browse files
refactor(php74): use null coalescing (??) and ??= operators
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
1 parent 5f5aad1 commit 0ba3429

5 files changed

Lines changed: 12 additions & 13 deletions

File tree

hmib.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3203,18 +3203,15 @@ function hmib_view_graphs() {
32033203

32043204
html_graph_validate_preview_request_vars();
32053205

3206-
if (!isset($_SESSION['sess_hmib_gt'])) {
3207-
$_SESSION['sess_hmib_gt'] = implode(',', array_rekey(db_fetch_assoc('SELECT DISTINCT gl.graph_template_id
3206+
$_SESSION['sess_hmib_gt'] ??= implode(',', array_rekey(db_fetch_assoc('SELECT DISTINCT gl.graph_template_id
32083207
FROM graph_local AS gl
32093208
WHERE gl.host_id IN(
32103209
SELECT host_id
32113210
FROM plugin_hmib_hrSystem
32123211
)'), 'graph_template_id', 'graph_template_id'));
3213-
}
32143212
$gt = $_SESSION['sess_hmib_gt'];
32153213

3216-
if (!isset($_SESSION['sess_hmib_hosts'])) {
3217-
$_SESSION['sess_hmib_hosts'] = implode(',', array_rekey(db_fetch_assoc('SELECT h.id
3214+
$_SESSION['sess_hmib_hosts'] ??= implode(',', array_rekey(db_fetch_assoc('SELECT h.id
32183215
FROM host AS h
32193216
WHERE h.id IN (
32203217
SELECT host_id
@@ -3226,7 +3223,6 @@ function hmib_view_graphs() {
32263223
INNER JOIN host_template AS ht
32273224
ON h.host_template_id=ht.id
32283225
WHERE hash="7c13344910097cc599f0d0485305361d" ORDER BY id DESC'), 'id', 'id'));
3229-
}
32303226
$hosts = $_SESSION['sess_hmib_hosts'];
32313227

32323228
/* include graph view filter selector */

hmib_types.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ function hmib_host_type_edit() {
801801
draw_edit_form(
802802
array(
803803
'config' => array('form_name' => 'chk'),
804-
'fields' => inject_form_variables($fields_host_type_edit, (isset($host_type) ? $host_type : array()))
804+
'fields' => inject_form_variables($fields_host_type_edit, ($host_type ?? array()))
805805
)
806806
);
807807

poller_graphs.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,8 @@ function hmib_gt_graph($host_id, $graph_template_id) {
306306
function add_summary_graphs($host_id, $host_template) {
307307
global $config;
308308

309-
$php_bin = read_config_option('path_php_binary');
310-
$base = $config['base_path'];
309+
$php_bin = cacti_escapeshellcmd(read_config_option('path_php_binary'));
310+
$base = cacti_escapeshellarg($config['base_path']);
311311

312312
$return_code = 0;
313313
if (empty($host_id)) {

poller_hmib.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ function hmib_dateParse($value) {
678678
$value[1] = substr($value[1], 0, strpos($value[1], '.'));
679679
}
680680

681-
$date1 = trim($value[0] . ' ' . (isset($value[1]) ? $value[1]:''));
681+
$date1 = trim($value[0] . ' ' . ($value[1] ?? ''));
682682
if (strtotime($date1) === false) {
683683
$value = date('Y-m-d H:i:s');
684684
} else {

snmp.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,10 @@
2727
define('SNMP_METHOD_PHP', 1);
2828
define('SNMP_METHOD_BINARY', 2);
2929

30-
if (!isset($banned_snmp_strings)) {
31-
$banned_snmp_strings = array(
30+
$banned_snmp_strings ??= array(
3231
'End of MIB',
3332
'No Such'
3433
);
35-
}
3634

3735
/* we must use an apostrophe to escape community names under Unix in case the user uses
3836
characters that the shell might interpret. */
@@ -131,6 +129,11 @@ function cacti_snmp_get($hostname, $community, $oid, $version, $username, $passw
131129
/* no valid snmp version has been set, get out */
132130
if (empty($snmp_auth)) { return; }
133131

132+
/* cast numeric args to int — prevents shell injection if the host record is tampered */
133+
$version = (int) $version;
134+
$timeout = (int) $timeout;
135+
$retries = (int) $retries;
136+
134137
exec(cacti_escapeshellcmd(read_config_option('path_snmpget')) . ' -O fntevU ' . $snmp_auth . " -v $version -t $timeout -r $retries " . cacti_escapeshellarg($hostname) . ":$port " . cacti_escapeshellarg($oid), $snmp_value);
135138

136139
/* fix for multi-line snmp output */

0 commit comments

Comments
 (0)