]> granicus.if.org Git - sysstat/commitdiff
mpstat: Fix untrusted loop bound
authorSebastien GODARD <sysstat@users.noreply.github.com>
Wed, 24 Nov 2021 17:33:08 +0000 (18:33 +0100)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Wed, 24 Nov 2021 17:33:08 +0000 (18:33 +0100)
Check that CPU value read from /proc/interrupts (or
/proc/softirqs) is within permissible range (CID#374284).

Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
mpstat.c

index 727a7eaeb46c1f4b91c255ed708e4faa7a0f56d8..f6bd2975d7b72f5e8334e585851d21ffcecc653b 100644 (file)
--- 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;
 
                                /*