Skip to content

Commit a90197d

Browse files
Merge commit from fork
Add bounds check before computing payLen to prevent uint8_t underflow when downlinkMsgLen is less than the minimum frame size (12 + fOptsLen). Returns RADIOLIB_ERR_DOWNLINK_MALFORMED for malformed frames. Fixes GHSA-xj4h-672x-ggwj Co-authored-by: lukegranto23 <seabreeze11971220@gmail.com>
1 parent 258d546 commit a90197d

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/protocols/LoRaWAN/LoRaWAN.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1896,7 +1896,12 @@ int16_t LoRaWANNode::parseDownlink(uint8_t* data, size_t* len, uint8_t window, L
18961896

18971897
// MHDR(1) - DevAddr(4) - FCtrl(1) - FCnt(2) - FOpts - Payload - MIC(4)
18981898
// potentially also an FPort, will find out next
1899-
uint8_t payLen = downlinkMsgLen - 1 - 4 - 1 - 2 - fOptsLen - 4;
1899+
// guard against integer underflow when downlinkMsgLen is too short
1900+
uint8_t minLen = 1 + 4 + 1 + 2 + fOptsLen + 4;
1901+
if(downlinkMsgLen < minLen) {
1902+
return(RADIOLIB_ERR_DOWNLINK_MALFORMED);
1903+
}
1904+
uint8_t payLen = downlinkMsgLen - minLen;
19001905

19011906
// in LoRaWAN v1.1, a frame is a Network frame if there is no Application payload
19021907
// i.e.: either no payload at all (empty frame or FOpts only), or MAC only payload

0 commit comments

Comments
 (0)