tools: Fix buffer overflow in hciattach_tialt.c
authorIldar Kamaletdinov <i.kamaletdinov@omp.ru>
Fri, 1 Apr 2022 12:16:43 +0000 (15:16 +0300)
committerAyush Garg <ayush.garg@samsung.com>
Mon, 15 May 2023 09:25:54 +0000 (14:55 +0530)
Array 'c_brf_chip' of size 8 could be accessed by index > 7. We should
limit array access like in previous check at line 221.

Found by Linux Verification Center (linuxtesting.org) with the SVACE
static analysis tool.

Signed-off-by: Manika Shrivastava <manika.sh@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
tools/hciattach_tialt.c

index 91fe579..a7e02c7 100755 (executable)
@@ -220,7 +220,8 @@ int texasalt_init(int fd, int speed, struct termios *ti)
                                ((brf_chip > 7) ? "unknown" : c_brf_chip[brf_chip]),
                                brf_chip);
 
-               sprintf(fw, "/etc/firmware/%s.bin", c_brf_chip[brf_chip]);
+               sprintf(fw, "/etc/firmware/%s.bin",
+                       (brf_chip > 7) ? "unknown" : c_brf_chip[brf_chip]);
                texas_load_firmware(fd, fw);
 
                texas_change_speed(fd, speed);