diff options
| author | riastradh <riastradh@NetBSD.org> | 2022-04-17 13:16:52 +0000 |
|---|---|---|
| committer | riastradh <riastradh@NetBSD.org> | 2022-04-17 13:16:52 +0000 |
| commit | 0090bd54d86cb67b82abde4dde060b4246945bbb (patch) | |
| tree | 9cdc246fbcec87574af02633c36268c92adbedb4 /sys/dev/usb | |
| parent | bdacf50fe352b20d2a5a7b676305953fd4c3998a (diff) | |
usbdi(9): Make usb_desc_iter_next_interface reject truncated descs.
Currently callers have to check whether the descriptor is truncated,
which is willy.
Diffstat (limited to 'sys/dev/usb')
| -rw-r--r-- | sys/dev/usb/usbdi_util.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/sys/dev/usb/usbdi_util.c b/sys/dev/usb/usbdi_util.c index 3a02a3c6e17..a4519855464 100644 --- a/sys/dev/usb/usbdi_util.c +++ b/sys/dev/usb/usbdi_util.c @@ -1,4 +1,4 @@ -/* $NetBSD: usbdi_util.c,v 1.86 2022/04/17 13:16:43 riastradh Exp $ */ +/* $NetBSD: usbdi_util.c,v 1.87 2022/04/17 13:16:52 riastradh Exp $ */ /* * Copyright (c) 1998, 2012 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: usbdi_util.c,v 1.86 2022/04/17 13:16:43 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: usbdi_util.c,v 1.87 2022/04/17 13:16:52 riastradh Exp $"); #ifdef _KERNEL_OPT #include "opt_usb.h" @@ -769,7 +769,11 @@ usb_desc_iter_next_interface(usbd_desc_iter_t *iter) usb_desc_iter_next(iter); } - return (const usb_interface_descriptor_t *)usb_desc_iter_next(iter); + if ((desc = usb_desc_iter_next(iter)) == NULL || + desc->bLength < sizeof(usb_interface_descriptor_t)) + return NULL; + KASSERT(desc->bDescriptorType == UDESC_INTERFACE); + return (const usb_interface_descriptor_t *)desc; } /* |
