File tree Expand file tree Collapse file tree 2 files changed +11
-11
lines changed Expand file tree Collapse file tree 2 files changed +11
-11
lines changed Original file line number Diff line number Diff line change @@ -1631,6 +1631,13 @@ static bool _parse_configuration_descriptor(uint8_t dev_addr, tusb_desc_configur
1631
1631
1632
1632
// parse each interfaces
1633
1633
while ( p_desc < desc_end ) {
1634
+ if ( 0 == tu_desc_len (p_desc ) ) {
1635
+ // A zero length descriptor indicates that the device is off spec (e.g. wrong wTotalLength).
1636
+ // Parsed interfaces should still be usable
1637
+ TU_LOG_USBH ("Encountered a zero-length descriptor after %u bytes\r\n" , (uint32_t )p_desc - (uint32_t )desc_cfg );
1638
+ break ;
1639
+ }
1640
+
1634
1641
uint8_t assoc_itf_count = 1 ;
1635
1642
1636
1643
// Class will always starts with Interface Association (if any) and then Interface descriptor
@@ -1645,13 +1652,6 @@ static bool _parse_configuration_descriptor(uint8_t dev_addr, tusb_desc_configur
1645
1652
// desc_iad->bFunctionClass == desc_itf->bInterfaceClass);
1646
1653
}
1647
1654
1648
- if ( 0 == tu_desc_len (p_desc ) ) {
1649
- // A zero length descriptor indicates that the wTotalLength field is wrong.
1650
- // Parsed interfaces should still be usable
1651
- TU_LOG_USBH ("Encountered a zero-length descriptor after %u bytes\r\n" , (uint32_t )p_desc - (uint32_t )desc_cfg );
1652
- break ;
1653
- }
1654
-
1655
1655
TU_ASSERT ( TUSB_DESC_INTERFACE == tu_desc_type (p_desc ) );
1656
1656
tusb_desc_interface_t const * desc_itf = (tusb_desc_interface_t const * ) p_desc ;
1657
1657
Original file line number Diff line number Diff line change @@ -247,6 +247,10 @@ uint16_t tu_desc_get_interface_total_len(tusb_desc_interface_t const* desc_itf,
247
247
p_desc = tu_desc_next (p_desc );
248
248
249
249
while (len < max_len ) {
250
+ if (tu_desc_len (p_desc ) == 0 ) {
251
+ // Escape infinite loop
252
+ break ;
253
+ }
250
254
// return on IAD regardless of itf count
251
255
if (tu_desc_type (p_desc ) == TUSB_DESC_INTERFACE_ASSOCIATION ) {
252
256
return len ;
@@ -255,10 +259,6 @@ uint16_t tu_desc_get_interface_total_len(tusb_desc_interface_t const* desc_itf,
255
259
((tusb_desc_interface_t const * ) p_desc )-> bAlternateSetting == 0 ) {
256
260
break ;
257
261
}
258
- if (tu_desc_len (p_desc ) == 0 ) {
259
- // Escape infinite loop
260
- break ;
261
- }
262
262
263
263
len += tu_desc_len (p_desc );
264
264
p_desc = tu_desc_next (p_desc );
You can’t perform that action at this time.
0 commit comments