monitor: Fix possible crash of rfcomm packet
authorYun-Hao Chung <howardchung@chromium.org>
Wed, 12 May 2021 02:36:06 +0000 (10:36 +0800)
committerAyush Garg <ayush.garg@samsung.com>
Fri, 11 Mar 2022 13:38:35 +0000 (19:08 +0530)
When RFCOMM_TEST_EA returns false, btmon assumes packet data has at
least 5 bytes long. If that assumption fails, btmon could crash when
trying to read the next byte.
This patch fix it by checking the remaining size before reading the last
byte.

Reviewed-by: apusaka@chromium.org
Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
monitor/rfcomm.c

index 114025d..950d8fc 100755 (executable)
@@ -451,6 +451,9 @@ void rfcomm_packet(const struct l2cap_frame *frame)
                hdr.length = GET_LEN16(hdr.length);
        }
 
+       if (!l2cap_frame->size)
+               goto fail;
+
        l2cap_frame_pull(&tmp_frame, l2cap_frame, l2cap_frame->size-1);
 
        if (!l2cap_frame_get_u8(&tmp_frame, &hdr.fcs))