Skip to content

Fix buffer-overflow assigning global Wire instances. #317

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

Merged
merged 1 commit into from
May 15, 2024

Conversation

aentinger
Copy link
Contributor

Two pointer arrays declared, which contain pointers to the global SCI/I2C Wire instances: "g_SCIWires" and "g_I2CWires". Since there's a different number of SCI vs pure I2C "I2C" interfaces those buffers are of different size. Due to a typo the constant declaring the size of the pointe rarray for "g_SCIWires" ("TWOWIRE_MAX_SCI_CHANNELS") was used to define the size of "g_I2CWires" and vice versa. This had the result that on Portenta C33, íf you were calling "TwoWire::_begin()" for "Wire3" (which has channel "3") a buffer overflow occurs and random memory is overwritten.

Two pointer arrays declared, which contain pointers to the global SCI/I2C Wire instances: "g_SCIWires" and "g_I2CWires". Since there's a different number of SCI vs pure I2C "I2C" interfaces those buffers are of different size. Due to a typo the constant declaring the size of the pointe rarray for "g_SCIWires" ("TWOWIRE_MAX_SCI_CHANNELS") was used to define the size of "g_I2CWires" and vice versa. This had the result that on Portenta C33, íf you were calling "TwoWire::_begin()" for "Wire3" (which has channel "3") a buffer overflow occurs and random memory is overwritten.
@aentinger aentinger added type: imperfection Perceived defect in any part of project topic: code Related to content of the project itself labels May 15, 2024
@aentinger aentinger requested review from facchinm and maidnl May 15, 2024 06:42
@aentinger aentinger self-assigned this May 15, 2024
@facchinm facchinm merged commit 9029d7d into main May 15, 2024
11 of 13 checks passed
@facchinm facchinm deleted the fix-buffer-overflow branch May 15, 2024 07:16
@sebromero
Copy link
Contributor

Brilliant @aentinger ! Thanks a lot for your help with this 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants