Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions database.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ function syslog_db_fetch_cell($sql, $col_name = '', $log = TRUE) {
return db_fetch_cell($sql, $col_name, $log, $syslog_cnn);
}

/* syslog_db_fetch_assoc_prepared - run a 'select' sql query and return the first column of the
first row found
@arg $sql - the sql query to run
@arg $params - the parameters to bind to the query
@arg $log - whether or not to log the query to the cacti log
@returns - the result of the query */
function syslog_db_fetch_assoc_prepared($sql, $params = array(), $log = TRUE) {
global $syslog_cnn;

return db_fetch_assoc_prepared($sql, $params, $log, $syslog_cnn);
}
Comment on lines +75 to +85
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new docblock for syslog_db_fetch_assoc_prepared() says it "return[s] the first column of the first row", but the function name and implementation indicate it returns an associative result set (via db_fetch_assoc_prepared). Please update the comment/@returns description to match the actual return type/behavior to avoid misleading future callers.

Copilot uses AI. Check for mistakes.

/* syslog_db_fetch_cell_prepared - run a 'select' sql query and return the first column of the
first row found
@param $sql - the sql query to execute
Expand Down
4 changes: 2 additions & 2 deletions syslog.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,10 @@ function syslog_statistics() {
$time = date($date_format, strtotime($r['insert_time']));

form_alternate_row();
echo '<td>' . (get_request_var('host') != '-2' ? $r['host']:'-') . '</td>';
echo '<td>' . (get_request_var('host') != '-2' ? htmle($r['host']):'-') . '</td>';
echo '<td>' . (get_request_var('facility') != '-2' ? ucfirst($r['facility']):'-') . '</td>';
echo '<td>' . (get_request_var('priority') != '-2' ? ucfirst($r['priority']):'-') . '</td>';
echo '<td>' . (get_request_var('program') != '-2' ? ucfirst($r['program']):'-') . '</td>';
echo '<td>' . (get_request_var('program') != '-2' ? htmle(ucfirst($r['program'])):'-') . '</td>';
Comment on lines 293 to +297
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

htmle() is introduced here, but this plugin repository does not define it (and existing output escaping in this file uses htmlspecialchars(...)). Unless htmle() is guaranteed by the hosting Cacti version, this will cause a runtime fatal error. Prefer using the established htmlspecialchars(..., ENT_QUOTES, 'UTF-8') pattern (or another known core escape helper already used/required by the plugin) to avoid an undeclared dependency.

Copilot uses AI. Check for mistakes.
//echo '<td class="right">' . $r['insert_time'] . '</td>';
echo '<td class="right">' . $time . '</td>';
echo '<td class="right">' . number_format_i18n($r['records'], -1) . '</td>';
Expand Down
47 changes: 30 additions & 17 deletions syslog_process.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,43 +272,56 @@
$smsalert = '';
$th_sql = '';

$params = array();
if ($alert['type'] == 'facility') {
$sql = 'SELECT * FROM `' . $syslogdb_default . '`.`syslog_incoming`
WHERE ' . $syslog_incoming_config['facilityField'] . "='" . $alert['message'] . "'
AND status=" . $uniqueID;
WHERE ' . $syslog_incoming_config['facilityField'] . '=?
AND status=?';
$params[] = $alert['message'];
$params[] = $uniqueID;
} else if ($alert['type'] == 'messageb') {
$sql = 'SELECT * FROM `' . $syslogdb_default . '`.`syslog_incoming`
WHERE ' . $syslog_incoming_config['textField'] . "
LIKE '" . $alert['message'] . "%'
AND status=" . $uniqueID;
WHERE ' . $syslog_incoming_config['textField'] . '
LIKE ?
AND status=?';
$params[] = $alert['message'] . '%';
$params[] = $uniqueID;
} else if ($alert['type'] == 'messagec') {
$sql = 'SELECT * FROM `' . $syslogdb_default . '`.`syslog_incoming`
WHERE ' . $syslog_incoming_config['textField'] . "
LIKE '%" . $alert['message'] . "%'
AND status=" . $uniqueID;
WHERE ' . $syslog_incoming_config['textField'] . '
LIKE ?
AND status=?';
$params[] = '%' . $alert['message'] . '%';
$params[] = $uniqueID;
} else if ($alert['type'] == 'messagee') {
$sql = 'SELECT * FROM `' . $syslogdb_default . '`.`syslog_incoming`
WHERE ' . $syslog_incoming_config['textField'] . "
LIKE '%" . $alert['message'] . "'
AND status=" . $uniqueID;
WHERE ' . $syslog_incoming_config['textField'] . '
LIKE ?
AND status=?';
$params[] = '%' . $alert['message'];
$params[] = $uniqueID;
} else if ($alert['type'] == 'host') {
$sql = 'SELECT * FROM `' . $syslogdb_default . '`.`syslog_incoming`
WHERE ' . $syslog_incoming_config['hostField'] . "='" . $alert['message'] . "'
AND status=" . $uniqueID;
WHERE ' . $syslog_incoming_config['hostField'] . '=?
AND status=?';
$params[] = $alert['message'];
$params[] = $uniqueID;
} else if ($alert['type'] == 'sql') {
$sql = 'SELECT * FROM `' . $syslogdb_default . '`.`syslog_incoming`
WHERE (' . $alert['message'] . ')
AND status=' . $uniqueID;
WHERE (?)
AND status=?';
$params[] = $alert['message'];
$params[] = $uniqueID;
}
Comment on lines 309 to 315
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 'sql' alert type query uses WHERE (?), but prepared-statement placeholders can only bind values, not SQL expressions. This will not apply the intended predicate (and may always evaluate truthy/falsey depending on DB), effectively breaking 'sql' alerts and not addressing SQL injection for this path. Consider either (a) removing/disabled the 'sql' type, (b) changing the feature to store a safe template with placeholders + separate bound params, or (c) parsing/whitelisting allowed columns/operators and building the WHERE clause with bound values (keeping status=? as a parameter).

Copilot uses AI. Check for mistakes.

if ($sql != '') {
if ($alert['method'] == '1') {
$th_sql = str_replace('*', 'count(*)', $sql);
$count = syslog_db_fetch_cell($th_sql);
$count = syslog_db_fetch_cell_prepared($th_sql, $params);
}

if (($alert['method'] == '1' && $count >= $alert['num']) || ($alert['method'] == '0')) {
$at = syslog_db_fetch_assoc($sql);
$at = syslog_db_fetch_assoc_prepared($sql, $params);

/* get a date for the repeat alert */
if ($alert['repeat_alert']) {
Expand Down
Loading