From 49d13df63cd9219585b0e05cc9c23bfb9a5aa2f3 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Fri, 13 Jun 2014 15:25:39 +0300 Subject: [PATCH] P2P: Fix wfd_dev_info parsing for P2P-DEVICE-FOUND (CID 68127) Commit b125c48fce823f28d22ebd68297c5b94366c6aa1 ('P2P: Add wfd_dev_info= field for device found event') added Wi-Fi Display device info to the P2P-DEVICE-FOUND events. However, it did not include proper bounds checking in wifi_display_subelem_hex() and could accept subelements with invalid length field values. This could result in buffer read overflow of up to 64 kB and inclusion of heap memory in the local control interface event and/or process crash due to invalid memory access. Fix this by checking the validity of the length field before writing a hexdump of the data. Signed-off-by: Jouni Malinen --- wpa_supplicant/wifi_display.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/wpa_supplicant/wifi_display.c b/wpa_supplicant/wifi_display.c index 8435b63a7..f0c43644d 100644 --- a/wpa_supplicant/wifi_display.c +++ b/wpa_supplicant/wifi_display.c @@ -276,6 +276,8 @@ char * wifi_display_subelem_hex(const struct wpabuf *wfd_subelems, u8 id) while (i + WIFI_DISPLAY_SUBELEM_HEADER_LEN < buflen) { elen = WPA_GET_BE16(buf + i + 1); + if (i + WIFI_DISPLAY_SUBELEM_HEADER_LEN + elen > buflen) + break; /* truncated subelement */ if (buf[i] == id) { subelem = os_zalloc(2 * elen + 1);