Skip to content

Commit e24b58a

Browse files
fix(security): validate $time input in syslog_partition_create
Addresses code review feedback on the PR Cacti#313 follow-up. The boundary epoch calculation ((int)($time / 86400) + 1) * 86400 assumes a non-negative UTC timestamp; non-numeric or pre-epoch values would silently underflow. Reject them at function entry with a logged error and a false return, matching the other guard clauses in the function. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
1 parent 602e3e9 commit e24b58a

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

functions.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,17 @@ function syslog_partition_create($table, $time = null) {
295295
$time = time() + 3600;
296296
}
297297

298+
// Reject non-numeric or pre-epoch timestamps; boundary math assumes a
299+
// non-negative UTC epoch so negative or bogus inputs cannot underflow
300+
// the (int)($time / 86400) + 1 computation below.
301+
if (!is_numeric($time) || (int)$time < 0) {
302+
cacti_log("SYSLOG ERROR: syslog_partition_create called with invalid time '$time' for table '$table'", false, 'SYSLOG');
303+
304+
return false;
305+
}
306+
307+
$time = (int)$time;
308+
298309
// Hash to guarantee the lock name stays within MySQL's 64-byte limit.
299310
$lock_name = substr(hash('sha256', $syslogdb_default . '.syslog_partition_create.' . $table), 0, 60);
300311

0 commit comments

Comments
 (0)