CRSF: Validate unknown packet sizes to be smaller than max packet size

Co-authored-by: Chris Seto <chris1seto@gmail.com>
This commit is contained in:
chris1seto 2022-09-24 13:36:17 -07:00 committed by GitHub
parent 57bdac2b26
commit 770f8080c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 0 deletions

View File

@ -294,6 +294,15 @@ bool CrsfParser_TryParseCrsfPacket(CrsfPacket_t *const new_packet, CrsfParserSta
// We don't know what this packet is, so we'll let the parser continue
// just so that we can dequeue it in one shot
working_segment_size = packet_size + PACKET_SIZE_TYPE_SIZE;
if (working_segment_size > CRSF_MAX_PACKET_LEN) {
parser_statistics->invalid_unknown_packet_sizes++;
parser_state = PARSER_STATE_HEADER;
working_segment_size = HEADER_SIZE;
working_index = 0;
buffer_count = QueueBuffer_Count(&rx_queue);
continue;
}
}
parser_state = PARSER_STATE_PAYLOAD;

View File

@ -69,6 +69,7 @@ struct CrsfParserStatistics_t {
uint32_t crcs_valid_unknown_packets;
uint32_t crcs_invalid;
uint32_t invalid_known_packet_sizes;
uint32_t invalid_unknown_packet_sizes;
};
enum CRSF_MESSAGE_TYPE {

View File

@ -504,6 +504,7 @@ int CrsfRc::print_status()
PX4_INFO("Valid unknown packet CRCs: %li", _packet_parser_statistics.crcs_valid_unknown_packets);
PX4_INFO("Invalid CRCs: %li", _packet_parser_statistics.crcs_invalid);
PX4_INFO("Invalid known packet sizes: %li", _packet_parser_statistics.invalid_known_packet_sizes);
PX4_INFO("Invalid unknown packet sizes: %li", _packet_parser_statistics.invalid_unknown_packet_sizes);
return 0;
}