btmon: fix segfault caused by integer undeflow
authorMatias Karhumaa <matias.karhumaa@gmail.com>
Tue, 16 Oct 2018 20:23:12 +0000 (23:23 +0300)
committerhimanshu <h.himanshu@samsung.com>
Tue, 14 Jan 2020 08:53:35 +0000 (14:23 +0530)
Fix segfault caused by integer underflow. Fix is to check that
rsp->num_codecs + 3 is not bigger than size before subtracting.

Crash was found by fuzzing btmon with AFL.

Change-Id: I9af6ee12b4bf58d33ee81412ddd6c47ef49acac8
Signed-off-by: himanshu <h.himanshu@samsung.com>
monitor/packet.c

index bb9a092..31b3169 100755 (executable)
@@ -5975,6 +5975,11 @@ static void read_local_codecs_rsp(const void *data, uint8_t size)
        const struct bt_hci_rsp_read_local_codecs *rsp = data;
        uint8_t i, num_vnd_codecs;
 
+       if (rsp->num_codecs + 3 > size) {
+               print_field("Invalid number of codecs.");
+               return;
+       }
+
        print_status(rsp->status);
        print_field("Number of supported codecs: %d", rsp->num_codecs);