Commit e3b17aa5 authored by Johann Fischer's avatar Johann Fischer Committed by Carles Cufi
Browse files

usb: host: improve robustness of descriptors print

Check that the length of the packet is at least the size of
the descriptor head. Otherwise there may be unpleasant side effects.

Signed-off-by: default avatarJohann Fischer <johann.fischer@nordicsemi.no>
parent 0a5b6824
Loading
Loading
Loading
Loading
+4 −0
Changes for subsys/usb/host/usbh_shell.c: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -61,6 +61,10 @@ static void print_desc(const struct shell *sh, const struct net_buf *const buf)
{
	struct usb_desc_header *head = (void *)buf->data;

	if (buf->len < sizeof(struct usb_desc_header)) {
		return;
	}

	switch (head->bDescriptorType) {
	case USB_DESC_DEVICE: {
		struct usb_device_descriptor *desc = (void *)buf->data;