Skip to content

Commit 1bad1d0

Browse files
author
Josuah Demangeon
committed
usb: host: ensure device configuration descriptors are nil-terminated
Allocate extra room at the end of the USB descriptor buffer to ensure that the device ends with `desc->bLength == 0`. For now, validating `desc->bLength` from the device to ensure no access past the buffer is still not done. Signed-off-by: Josuah Demangeon <[email protected]>
1 parent 0054ae9 commit 1bad1d0

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

subsys/usb/host/usbh_device.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ int usbh_device_set_configuration(struct usb_device *const udev, const uint8_t n
397397
}
398398

399399
udev->cfg_desc = k_heap_alloc(&usb_device_heap,
400-
cfg_desc.wTotalLength,
400+
cfg_desc.wTotalLength + sizeof(struct usb_desc_header),
401401
K_NO_WAIT);
402402
if (udev->cfg_desc == NULL) {
403403
LOG_ERR("Failed to allocate memory for configuration descriptor");

0 commit comments

Comments
 (0)