From b6b47f0259effb300012e14fc2a4528f4120a2ad Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 27 Feb 2025 06:30:34 +0100 Subject: [PATCH] Return early if we cannot parse the total cpu line in /proc/stat Signed-off-by: DL6ER --- src/procps.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/procps.c b/src/procps.c index 3d71e3d94..e74c57754 100644 --- a/src/procps.c +++ b/src/procps.c @@ -323,16 +323,23 @@ bool parse_proc_stat(unsigned long *total_sum, unsigned long *idle_sum) { if(strncmp(line, "cpu ", 4) == 0) { - sscanf(line, "cpu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu", + if(sscanf(line, "cpu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu", &user, &nice, &system, &idle, &iowait, &irq, &softirq, &steal, - &guest, &guest_nice); + &guest, &guest_nice) != 10) + { + log_debug(DEBUG_ANY, "Failed to parse CPU line in /proc/stat"); + fclose(statfile); + return false; + } + break; } } if (feof(statfile)) { log_warn("No CPU line found in /proc/stat"); + fclose(statfile); return false; }