Skip to content

Commit

Permalink
Return early if we cannot parse the total cpu line in /proc/stat
Browse files Browse the repository at this point in the history
Signed-off-by: DL6ER <[email protected]>
  • Loading branch information
DL6ER committed Feb 27, 2025
1 parent 1102aa1 commit b6b47f0
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/procps.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit b6b47f0

Please sign in to comment.