From 5d5a204006a3685e07e98ad92200b468c781bed9 Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Wed, 24 Nov 2021 18:33:08 +0100 Subject: [PATCH] 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 --- mpstat.c | 2 ++ 1 file changed, 2 insertions(+) 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; /* -- 2.40.0