From be52cd8edd64e144adaa53f9dce8eae5994c7c3f Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 14 Jan 2024 16:33:17 +0100 Subject: [PATCH] [LoRaWAN] Fix possible integer overflow --- src/protocols/LoRaWAN/LoRaWAN.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/protocols/LoRaWAN/LoRaWAN.cpp b/src/protocols/LoRaWAN/LoRaWAN.cpp index dbf18ed3..130811e9 100644 --- a/src/protocols/LoRaWAN/LoRaWAN.cpp +++ b/src/protocols/LoRaWAN/LoRaWAN.cpp @@ -1898,7 +1898,7 @@ uint32_t LoRaWANNode::dutyCycleInterval(uint32_t msPerHour, uint32_t airtime) { if(msPerHour == 0 || airtime == 0) { return(0); } - uint32_t oneHourInMs = 60 * 60 * 1000; + uint32_t oneHourInMs = (uint32_t)60 * (uint32_t)60 * (uint32_t)1000; float numPackets = msPerHour / airtime; uint32_t delayMs = oneHourInMs / numPackets + 1; // + 1 to prevent rounding problems return(delayMs); @@ -2244,7 +2244,7 @@ bool LoRaWANNode::execMacCommand(LoRaWANMacCommand_t* cmd, bool saveToEeprom) { if(maxDutyCycle == 0) { this->dutyCycle = this->band->dutyCycle; } else { - this->dutyCycle = 60 * 60 * 1000 / (1 << maxDutyCycle); + this->dutyCycle = (uint32_t)60 * (uint32_t)60 * (uint32_t)1000 / (uint32_t)(1UL << maxDutyCycle); } #if !defined(RADIOLIB_EEPROM_UNSUPPORTED)