From 68f924b191ed999ecfc4f2a8a38b6f46bceda547 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Wed, 15 May 2024 08:37:20 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20buffer-overflow=20assigning=20global=20Wi?= =?UTF-8?q?re=20instances.=20Two=20pointer=20arrays=20declared,=20which=20?= =?UTF-8?q?contain=20pointers=20to=20the=20global=20SCI/I2C=20Wire=20insta?= =?UTF-8?q?nces:=20"g=5FSCIWires"=20and=20"g=5FI2CWires".=20Since=20there'?= =?UTF-8?q?s=20a=20different=20number=20of=20SCI=20vs=20pure=20I2C=20"I2C"?= =?UTF-8?q?=20interfaces=20those=20buffers=20are=20of=20different=20size.?= =?UTF-8?q?=20Due=20to=20a=20typo=20the=20constant=20declaring=20the=20siz?= =?UTF-8?q?e=20of=20the=20pointe=20rarray=20for=20"g=5FSCIWires"=20("TWOWI?= =?UTF-8?q?RE=5FMAX=5FSCI=5FCHANNELS")=20was=20used=20to=20define=20the=20?= =?UTF-8?q?size=20of=20"g=5FI2CWires"=20and=20vice=20versa.=20This=20had?= =?UTF-8?q?=20the=20result=20that=20on=20Portenta=20C33,=20=C3=ADf=20you?= =?UTF-8?q?=20were=20calling=20"TwoWire::=5Fbegin()"=20for=20"Wire3"=20(wh?= =?UTF-8?q?ich=20has=20channel=20"3")=20a=20buffer=20overflow=20occurs=20a?= =?UTF-8?q?nd=20random=20memory=20is=20overwritten.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libraries/Wire/Wire.cpp | 4 ++-- libraries/Wire/Wire.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/Wire/Wire.cpp b/libraries/Wire/Wire.cpp index 792364268..c7561ea83 100644 --- a/libraries/Wire/Wire.cpp +++ b/libraries/Wire/Wire.cpp @@ -30,8 +30,8 @@ extern "C" { #include "Wire.h" -TwoWire *TwoWire::g_SCIWires[TWOWIRE_MAX_I2C_CHANNELS] = {nullptr}; -TwoWire *TwoWire::g_I2CWires[TWOWIRE_MAX_SCI_CHANNELS] = {nullptr}; +TwoWire *TwoWire::g_SCIWires[TWOWIRE_MAX_SCI_CHANNELS] = {nullptr}; +TwoWire *TwoWire::g_I2CWires[TWOWIRE_MAX_I2C_CHANNELS] = {nullptr}; /* -------------------------------------------------------------------------- */ void TwoWire::setBusStatus(WireStatus_t ws) { diff --git a/libraries/Wire/Wire.h b/libraries/Wire/Wire.h index 5a78660b1..88ff8d652 100644 --- a/libraries/Wire/Wire.h +++ b/libraries/Wire/Wire.h @@ -152,8 +152,8 @@ class TwoWire : public arduino::HardwareI2C { private: - static TwoWire *g_SCIWires[TWOWIRE_MAX_I2C_CHANNELS]; - static TwoWire *g_I2CWires[TWOWIRE_MAX_SCI_CHANNELS]; + static TwoWire *g_SCIWires[TWOWIRE_MAX_SCI_CHANNELS]; + static TwoWire *g_I2CWires[TWOWIRE_MAX_I2C_CHANNELS]; static void WireSCIMasterCallback(i2c_master_callback_args_t *); static void WireMasterCallback(i2c_master_callback_args_t *);