From 0117231208615c1f831c8026e79b6ddad136974b Mon Sep 17 00:00:00 2001 From: Marek NOVAK Date: Wed, 3 Jul 2024 07:03:05 +0200 Subject: [PATCH] Add sanity check to sx126x driver when handling retention list --- src/radio/sx126x/radio.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/radio/sx126x/radio.c b/src/radio/sx126x/radio.c index c4a40dab8..abe128c08 100644 --- a/src/radio/sx126x/radio.c +++ b/src/radio/sx126x/radio.c @@ -1119,9 +1119,16 @@ void RadioAddRegisterToRetentionList( uint16_t registerAddress ) // Read the address and registers already added to the list SX126xReadRegisters( REG_RETENTION_LIST_BASE_ADDRESS, buffer, 9 ); - const uint8_t nbOfRegisters = buffer[0]; + uint8_t nbOfRegisters = buffer[0]; uint8_t* registerList = &buffer[1]; + // in case more than maximum read -> set to 0 + if(nbOfRegisters > MAX_NB_REG_IN_RETENTION) + { + nbOfRegisters = 0; + buffer[0] = 0; // set also to zero - invalid value was read-out + } + // Check if the register given as parameter is already added to the list for( uint8_t i = 0; i < nbOfRegisters; i++ ) {