Fix index value used in online_cpu_bitmap array
authorSebastien GODARD <sysstat@users.noreply.github.com>
Mon, 10 Jan 2022 16:57:25 +0000 (17:57 +0100)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Mon, 10 Jan 2022 16:57:25 +0000 (17:57 +0100)
The online_cpu_bitmap[] array size is based on the number of CPU
allocated (see sa_wrap.c:wrap_read_softnet()). The size is calculated as
BITMAP_SIZE(a->nr_allocated).
So the index used in read_softnet() function (rd_stats.c) shall not
exceed the size of the array, and so cannot reach NR_CPUS.

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

index ec074200d4b1cfd8d41a84215acb438cbf1cb044..f3d9527a0e3a44b075b3c84eade5f0bce0b9d907 100644 (file)
@@ -2741,14 +2741,11 @@ int read_softnet(struct stats_softnet *st_softnet, __nr_t nr_alloc,
 
        while (fgets(line, sizeof(line), fp) != NULL) {
 
-               while ((!(online_cpu_bitmap[(cpu - 1) >> 3] & (1 << ((cpu - 1) & 0x07)))) && (cpu <= NR_CPUS + 1)) {
+               while ((!(online_cpu_bitmap[(cpu - 1) >> 3] & (1 << ((cpu - 1) & 0x07)))) && (cpu < nr_alloc)) {
                        cpu++;
                }
-               if (cpu > NR_CPUS + 1)
-                       /* Should never happen */
-                       return 0;
 
-               if (cpu + 1 > nr_alloc) {
+               if (cpu >= nr_alloc) {
                        rc = -1;
                        break;
                }