Skip to content

Commit

Permalink
[LoRaWAN] Properly size fopts buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
jgromes committed Jan 14, 2024
1 parent 8c5ae6d commit efe303c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/protocols/LoRaWAN/LoRaWAN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1417,7 +1417,11 @@ int16_t LoRaWANNode::downlink(uint8_t* data, size_t* len, LoRaWANEvent_t* event)
// process FOpts (if there are any)
if(foptsLen > 0) {
// there are some Fopts, decrypt them
uint8_t fopts[RADIOLIB_LORAWAN_FHDR_FOPTS_LEN_MASK];
#if !RADIOLIB_STATIC_ONLY
uint8_t* fopts = new uint8_t[RADIOLIB_MAX(RADIOLIB_LORAWAN_FHDR_FOPTS_LEN_MASK, (int)foptsLen)];
#else
uint8_t fopts[RADIOLIB_STATIC_ARRAY_SIZE];
#endif

// TODO it COULD be the case that the assumed FCnt rollover is incorrect, if possible figure out a way to catch this and retry with just fcnt16
// if there are <= 15 bytes of FOpts, they are in the FHDR, otherwise they are in the payload
Expand Down Expand Up @@ -1462,6 +1466,10 @@ int16_t LoRaWANNode::downlink(uint8_t* data, size_t* len, LoRaWANEvent_t* event)
RADIOLIB_DEBUG_PRINTLN("Processed: %d, remaining: %d", (macLen + 1), remLen);
}

#if !RADIOLIB_STATIC_ONLY
delete[] fopts;
#endif

RADIOLIB_DEBUG_PRINTLN("MAC response:");
for (int i = 0; i < this->commandsUp.numCommands; i++) {
RADIOLIB_DEBUG_HEXDUMP(&(this->commandsUp.commands[i].cid), sizeof(LoRaWANMacCommand_t));
Expand Down

0 comments on commit efe303c

Please sign in to comment.