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

OHCI: Fix array out of bounds issue #1305

Merged
merged 1 commit into from Feb 1, 2022
Merged

Conversation

Ryzee119
Copy link
Contributor

Describe the PR
If using a USB hub with OHCI host backend will result in a array index out of bounds error.

Additional context
Original line:

}control[CFG_TUH_DEVICE_MAX+1];

It can happen in a few places but one such example is here:

ohci_ed_t* ed = &ohci_data.control[dev_addr].ed;

ie. As HUB addresses are >=5, this results in a array index out of bounds on control endpoints as CFG_TUH_DEVICE_MAX+1 is only 5 with HUBs enabled..

This fix just includes num of hubs in the reserved array size.
Changing this locally fixed my issue issue.

If using a USB hub, a request outside the array size can occur

Original line:
https://github.com/hathach/tinyusb/blob/ffb257ac17f162bc5a4c26596d7a1e954db98aa5/src/portable/ohci/ohci.h#L162

It can happen in a few places but one such example is here:
https://github.com/hathach/tinyusb/blob/ffb257ac17f162bc5a4c26596d7a1e954db98aa5/src/portable/ohci/ohci.c#L460

ie. if HUB address is 5, this would be an array index out of bounds on control endpoints as `CFG_TUH_DEVICE_MAX+1` is only 5.

This fix just includes num of hubs in the reserve array size.

Fixing locally fixed this issue.
Copy link
Owner

@hathach hathach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this code used to work but ohci is getting behind host updates/refactoring

@hathach hathach merged commit c6cde72 into hathach:master Feb 1, 2022
@Ryzee119 Ryzee119 deleted the patch-1 branch September 20, 2022 23:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants