command-nas: fix out-of-bounds read
authorDaniel Golle <daniel@makrotopia.org>
Mon, 22 Nov 2021 01:19:05 +0000 (01:19 +0000)
committerDaniel Golle <daniel@makrotopia.org>
Mon, 22 Nov 2021 01:23:33 +0000 (01:23 +0000)
Limit iteration to number of array members fixing potential
out-of-bounds read.

Coverity CID: 1493471 Out-of-bounds read
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
commands-nas.c

index 123ba636987106369e536ab7820b35f9a97f0975..01ca3b8a1699d2de94dd0ba7200e65d8ad14a2d2 100644 (file)
@@ -83,7 +83,7 @@ print_earfcn_info(uint32_t earfcn)
                { 45590, 46589, 44, 700,  "TDD" },
        };
 
-       for (int i = 0; i < sizeof(earfcn_ranges); i++) {
+       for (int i = 0; i < (sizeof(earfcn_ranges) / sizeof(*earfcn_ranges)); i++) {
                if (earfcn <= earfcn_ranges[i].max && earfcn >= earfcn_ranges[i].min) {
                        blobmsg_add_u32(&status, "band", earfcn_ranges[i].band);
                        blobmsg_add_u32(&status, "frequency", earfcn_ranges[i].freq);