Skip to content

Commit 4a3307d

Browse files
committed
AP_ADSB: avoid buffer overwrite in AP_ADSB_Sagetech_MXS
we were not bounds-checking the off-wire length, and then reading many bytes into a target buffer based on it. Do the bounds check. Also remove the writing of the checksum into the payload buffer - this was the notional 1-byte overwrite
1 parent 4d25361 commit 4a3307d

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

libraries/AP_ADSB/AP_ADSB_Sagetech_MXS.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,10 @@ bool AP_ADSB_Sagetech_MXS::parse_byte(const uint8_t data)
279279
case ParseState::WaitingFor_PayloadLen:
280280
message_in.checksum += data;
281281
message_in.packet.payload_length = data;
282+
if (message_in.packet.payload_length > ARRAY_SIZE(message_in.packet.payload)) {
283+
message_in.state = ParseState::WaitingFor_Start;
284+
break;
285+
}
282286
message_in.index = 0;
283287
message_in.state = (data == 0) ? ParseState::WaitingFor_Checksum : ParseState::WaitingFor_PayloadContents;
284288
break;
@@ -293,7 +297,6 @@ bool AP_ADSB_Sagetech_MXS::parse_byte(const uint8_t data)
293297
message_in.state = ParseState::WaitingFor_Start;
294298
if (message_in.checksum == data) {
295299
// append the checksum to the payload and zero out the payload index
296-
message_in.packet.payload[message_in.index] = data;
297300
message_in.index = 0;
298301
handle_packet(message_in.packet);
299302
}

0 commit comments

Comments
 (0)