USBH config descriptor parsing buggy #149
Labels
bug
Something isn't working
internal bug tracker
Issue confirmed and logged into the internal bug tracking system
mw
Middleware-related issue or pull-request.
usb
Universal Serial Bus
Describe the set-up
Describe the bug
My OnePlus 8 Pro provides different USB config descriptor dependent on its current situation.
I would expect that all the descriptor could be parsed but this seems not to be the case.
The problem itself is not hardware dependent.
I captured the different config descriptor provided by my phone and extract the parsing code to a stand alone project. So I could inspect the failure in a simple test.
How To Reproduce
Additional context
Here the three USB config descriptors:
The function does not return because the current implementation will lead to the situation that a call to
returns the same pdesc pointer as has been provided. This is caused because
pdesc->bLength == 0
.This is currently not really be caused by the provided config descriptor but how the descriptor is handled by your parsing code.
Regardless which situation results into a length of zero, the function should be hardened to not enter and endless loop.
This could be done simple by replacing the two calls to get next desc with code like this:
But IMHO the real buggy behaviour is that the config descriptor is not parsed as given but there are some magic corrections
This seems strange to me.
As you can see there are 4 endpoints (type 0x05) in the third descriptor:
two uses a length of 0x09 and two uses a length of 0x07.
Your code ignores the given length of 0x09 and set
USB_ENDPOINT_DESC_SIZE
(0x07U) as length.This will corrupt the whole data handling as pdesc / ptr will not be increased by the 9 bytes but only by 7 and so the whole further data is not inspected at the correct byte places.
The text was updated successfully, but these errors were encountered: