From 972841451cd2494b5dacdc147a5e6be024c6ed79 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Wed, 13 May 2020 17:42:57 +0200 Subject: [PATCH] mesh: add assert for network pdu len in relay message --- src/mesh/mesh_network.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/mesh/mesh_network.c b/src/mesh/mesh_network.c index fe9c61858..7392aeafa 100644 --- a/src/mesh/mesh_network.c +++ b/src/mesh/mesh_network.c @@ -418,15 +418,18 @@ static void mesh_network_relay_message(mesh_network_pdu_t * network_pdu){ uint8_t ctl_in_bit_7 = ctl_ttl & 0x80; uint8_t ttl = ctl_ttl & 0x7f; + // prepare pdu for resending + network_pdu->data[1] = ctl_in_bit_7 | (ttl - 1); + network_pdu->flags |= MESH_NETWORK_PDU_FLAGS_RELAY; + #ifdef LOG_NETWORK printf("TX-Relay-NetworkPDU (%p): ", network_pdu); printf_hexdump(network_pdu->data, network_pdu->len); printf("^^ into network_pdus_queued\n"); #endif - // prepare pdu for resending - network_pdu->data[1] = ctl_in_bit_7 | (ttl - 1); - network_pdu->flags |= MESH_NETWORK_PDU_FLAGS_RELAY; + uint8_t net_mic_len = ctl_in_bit_7 ? 8 : 4; + btstack_assert((network_pdu->len + net_mic_len) <= 29); // queue up btstack_linked_list_add_tail(&network_pdus_queued, (btstack_linked_item_t *) network_pdu);