Skip to content

Commit 68f924b

Browse files
committed
Fix buffer-overflow assigning global Wire instances.
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.
1 parent 74921ae commit 68f924b

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

libraries/Wire/Wire.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ extern "C" {
3030

3131
#include "Wire.h"
3232

33-
TwoWire *TwoWire::g_SCIWires[TWOWIRE_MAX_I2C_CHANNELS] = {nullptr};
34-
TwoWire *TwoWire::g_I2CWires[TWOWIRE_MAX_SCI_CHANNELS] = {nullptr};
33+
TwoWire *TwoWire::g_SCIWires[TWOWIRE_MAX_SCI_CHANNELS] = {nullptr};
34+
TwoWire *TwoWire::g_I2CWires[TWOWIRE_MAX_I2C_CHANNELS] = {nullptr};
3535

3636
/* -------------------------------------------------------------------------- */
3737
void TwoWire::setBusStatus(WireStatus_t ws) {

libraries/Wire/Wire.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ class TwoWire : public arduino::HardwareI2C {
152152

153153
private:
154154

155-
static TwoWire *g_SCIWires[TWOWIRE_MAX_I2C_CHANNELS];
156-
static TwoWire *g_I2CWires[TWOWIRE_MAX_SCI_CHANNELS];
155+
static TwoWire *g_SCIWires[TWOWIRE_MAX_SCI_CHANNELS];
156+
static TwoWire *g_I2CWires[TWOWIRE_MAX_I2C_CHANNELS];
157157

158158
static void WireSCIMasterCallback(i2c_master_callback_args_t *);
159159
static void WireMasterCallback(i2c_master_callback_args_t *);

0 commit comments

Comments
 (0)