summaryrefslogtreecommitdiff
path: root/src/host
diff options
context:
space:
mode:
authorGuavTek <[email protected]>2024-10-18 18:05:58 +0200
committerGuavTek <[email protected]>2024-10-18 18:05:58 +0200
commitebcd7067c9b86b8df8a3f9cf07ba76edd9e7440c (patch)
tree0254e10210e3ff72e5028eaaa9546d08e9cc252a /src/host
parent8b1e40c3e2447de5b4a86bbcdcc0344946a4793d (diff)
Recover host enumeration from zero length descriptors
Diffstat (limited to 'src/host')
-rw-r--r--src/host/usbh.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/host/usbh.c b/src/host/usbh.c
index b5df29f50..1b45fd1be 100644
--- a/src/host/usbh.c
+++ b/src/host/usbh.c
@@ -1645,6 +1645,13 @@ static bool _parse_configuration_descriptor(uint8_t dev_addr, tusb_desc_configur
// desc_iad->bFunctionClass == desc_itf->bInterfaceClass);
}
+ if ( 0 == tu_desc_len(p_desc) ) {
+ // A zero length descriptor indicates that the wTotalLength field is wrong.
+ // Parsed interfaces should still be usable
+ TU_LOG_USBH("Encountered a zero-length descriptor after %u bytes\r\n", (uint32_t)p_desc - (uint32_t)desc_cfg);
+ break;
+ }
+
TU_ASSERT( TUSB_DESC_INTERFACE == tu_desc_type(p_desc) );
tusb_desc_interface_t const* desc_itf = (tusb_desc_interface_t const*) p_desc;