Fixed handling of too small packets
If a packet of only 1 byte was received (which only can happen due to noise), a segmentation fault could occur because the CRC expects at least two bytes. This is now handled correctly.
This commit is contained in:
parent
f7a0186f4f
commit
440382da57
3 changed files with 24 additions and 3 deletions
|
|
@ -105,7 +105,14 @@ result_t connection_handle_packet(connection_ctx_t *ctx, const uint8_t *buf, siz
|
|||
data_packet->payload_len = 0;
|
||||
|
||||
// check the CRC
|
||||
size_t packet_size = buf_len - crc_sizeof_key(PAYLOAD_CRC_SCHEME);
|
||||
size_t crc_size = crc_sizeof_key(PAYLOAD_CRC_SCHEME);
|
||||
|
||||
if(buf_len < (crc_size+1)) {
|
||||
LOG(LVL_ERR, "packet is too small: %u bytes; required: %u bytes", buf_len, (crc_size+1));
|
||||
return ERR_INTEGRITY;
|
||||
}
|
||||
|
||||
size_t packet_size = buf_len - crc_size;
|
||||
|
||||
if(!crc_check_key(PAYLOAD_CRC_SCHEME, (unsigned char*)buf, packet_size)) {
|
||||
LOG(LVL_ERR, "payload CRC check failed!");
|
||||
|
|
|
|||
|
|
@ -106,7 +106,14 @@ result_t digipeater_handle_packet(
|
|||
data_packet->payload_len = 0;
|
||||
|
||||
// check the CRC
|
||||
size_t packet_size = buf_len - crc_sizeof_key(PAYLOAD_CRC_SCHEME);
|
||||
size_t crc_size = crc_sizeof_key(PAYLOAD_CRC_SCHEME);
|
||||
|
||||
if(buf_len < (crc_size+1)) {
|
||||
LOG(LVL_ERR, "packet is too small: %u bytes; required: %u bytes", buf_len, (crc_size+1));
|
||||
return ERR_INTEGRITY;
|
||||
}
|
||||
|
||||
size_t packet_size = buf_len - crc_size;
|
||||
|
||||
if(!crc_check_key(PAYLOAD_CRC_SCHEME, (unsigned char*)buf, packet_size)) {
|
||||
LOG(LVL_ERR, "CRC check failed!");
|
||||
|
|
|
|||
|
|
@ -38,7 +38,14 @@ void layer2_rx_destroy(layer2_rx_t *ctx)
|
|||
result_t layer2_rx_handle_packet(layer2_rx_t *ctx, const uint8_t *buf, size_t buf_len, bool *shall_ack)
|
||||
{
|
||||
// check the CRC
|
||||
size_t packet_size = buf_len - crc_sizeof_key(PAYLOAD_CRC_SCHEME);
|
||||
size_t crc_size = crc_sizeof_key(PAYLOAD_CRC_SCHEME);
|
||||
|
||||
if(buf_len < (crc_size+1)) {
|
||||
LOG(LVL_ERR, "packet is too small: %u bytes; required: %u bytes", buf_len, (crc_size+1));
|
||||
return ERR_INTEGRITY;
|
||||
}
|
||||
|
||||
size_t packet_size = buf_len - crc_size;
|
||||
|
||||
if(!crc_check_key(PAYLOAD_CRC_SCHEME, (unsigned char*)buf, packet_size)) {
|
||||
LOG(LVL_ERR, "payload CRC check failed!");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue