Skip to content

Commit 11f4348

Browse files
committed
transport/usb: Fix potential buffer overrun
When HCI command was received from USB transport cmd_len was not checked and was used for memcpy. It could lead to memory corruption if USB stack called this function with size exceeding maximum command size. This is currently possible scenario with TinyUSB stack (it will be fixed there as well).
1 parent 891a0c9 commit 11f4348

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

nimble/transport/usb/src/ble_hci_usb.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ tud_bt_hci_cmd_cb(void *hci_cmd, size_t cmd_len)
229229
if (ble_hci_usb_rx_cmd_ll_cb) {
230230
buf = ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_CMD);
231231
assert(buf != NULL);
232-
memcpy(buf, hci_cmd, cmd_len);
232+
memcpy(buf, hci_cmd, min(cmd_len, BLE_HCI_TRANS_CMD_SZ));
233233

234234
rc = ble_hci_usb_rx_cmd_ll_cb(buf, ble_hci_usb_rx_cmd_ll_arg);
235235
}

0 commit comments

Comments
 (0)