From: Sebastien GODARD Date: Wed, 24 Nov 2021 17:33:08 +0000 (+0100) Subject: mpstat: Fix untrusted loop bound X-Git-Tag: v12.5.5~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5d5a204006a3685e07e98ad92200b468c781bed9;p=sysstat mpstat: Fix untrusted loop bound Check that CPU value read from /proc/interrupts (or /proc/softirqs) is within permissible range (CID#374284). Signed-off-by: Sebastien GODARD --- diff --git a/mpstat.c b/mpstat.c index 727a7ea..f6bd297 100644 --- a/mpstat.c +++ b/mpstat.c @@ -1827,6 +1827,8 @@ void read_interrupts_stat(char *file, struct stats_irqcpu *st_ic[], int ic_nr, i next = line; while (((cp = strstr(next, "CPU")) != NULL) && (index < cpu_nr)) { cpu = strtol(cp + 3, &next, 10); + if (cpu >= cpu_nr) + break; cpu_index[index++] = cpu; /*