Skip to content

Commit

Permalink
Merge pull request #2852 from GuavTek/recover_zero_length_desc
Browse files Browse the repository at this point in the history
USBH: Recover from unexpected descriptor size
  • Loading branch information
hathach authored Nov 28, 2024
2 parents 5bb90ef + 3cacb01 commit 3142927
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/host/usbh.c
Original file line number Diff line number Diff line change
Expand Up @@ -1654,6 +1654,13 @@ static bool _parse_configuration_descriptor(uint8_t dev_addr, tusb_desc_configur

// parse each interfaces
while( p_desc < desc_end ) {
if ( 0 == tu_desc_len(p_desc) ) {
// A zero length descriptor indicates that the device is off spec (e.g. wrong wTotalLength).
// 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;
}

uint8_t assoc_itf_count = 1;

// Class will always starts with Interface Association (if any) and then Interface descriptor
Expand Down
4 changes: 4 additions & 0 deletions src/tusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ uint16_t tu_desc_get_interface_total_len(tusb_desc_interface_t const* desc_itf,
p_desc = tu_desc_next(p_desc);

while (len < max_len) {
if (tu_desc_len(p_desc) == 0) {
// Escape infinite loop
break;
}
// return on IAD regardless of itf count
if (tu_desc_type(p_desc) == TUSB_DESC_INTERFACE_ASSOCIATION) {
return len;
Expand Down

0 comments on commit 3142927

Please sign in to comment.