Skip to content

Commit e8ecb6c

Browse files
Josuah Demangeonkartben
authored andcommitted
usb: host: check that descriptor is in bound before dereferencing
In the while loop parsing descriptors, check that the descriptor is past the end just before dereferencing it to check if it is seemingly valid. Signed-off-by: Josuah Demangeon <[email protected]>
1 parent a6faa0c commit e8ecb6c

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
@@ -285,7 +285,7 @@ static int parse_configuration_descriptor(struct usb_device *const udev)
285285
dhp = (void *)((uint8_t *)udev->cfg_desc + cfg_desc->bLength);
286286
desc_end = (void *)((uint8_t *)udev->cfg_desc + cfg_desc->wTotalLength);
287287

288-
while ((dhp->bDescriptorType != 0 || dhp->bLength != 0) && (void *)dhp < desc_end) {
288+
while ((void *)dhp < desc_end && (dhp->bDescriptorType != 0 || dhp->bLength != 0)) {
289289
if (dhp->bDescriptorType == USB_DESC_INTERFACE_ASSOC) {
290290
iad = (struct usb_association_descriptor *)dhp;
291291
LOG_DBG("bFirstInterface %u", iad->bFirstInterface);

0 commit comments

Comments
 (0)