Fixed handling of too small packets
All checks were successful
/ build-hamnet70 (push) Successful in 39s
/ build-doc (push) Successful in 19s
/ deploy-doc (push) Has been skipped

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:
Thomas Kolb 2025-10-26 20:23:46 +01:00
commit 440382da57
3 changed files with 24 additions and 3 deletions

View file

@ -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!");

View file

@ -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!");

View file

@ -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!");