Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USBH: Recover from unexpected descriptor size #2852

Merged
merged 3 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/host/usbh.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) ) {
hathach marked this conversation as resolved.
Show resolved Hide resolved
// 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;

Expand Down
4 changes: 4 additions & 0 deletions src/tusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ uint16_t tu_desc_get_interface_total_len(tusb_desc_interface_t const* desc_itf,
((tusb_desc_interface_t const*) p_desc)->bAlternateSetting == 0) {
break;
}
if (tu_desc_len(p_desc) == 0) {
hathach marked this conversation as resolved.
Show resolved Hide resolved
// Escape infinite loop
break;
}

len += tu_desc_len(p_desc);
p_desc = tu_desc_next(p_desc);
Expand Down