Skip to content

Commit 0bb3a0e

Browse files
committed
Add minimum payload_len check for TRACE packet parsing
The TRACE handler reads 9 bytes (trace_tag, auth_code, flags) from the payload before any length validation. A short TRACE packet causes reads of stale buffer data and an underflow in the remaining-length calculation (uint8_t len = payload_len - 9 wraps to ~247). Add payload_len >= 9 to the existing guard condition so undersized TRACE packets are silently dropped.
1 parent fb726e4 commit 0bb3a0e

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/Mesh.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ int Mesh::searchChannelsByHash(const uint8_t* hash, GroupChannel channels[], int
4040

4141
DispatcherAction Mesh::onRecvPacket(Packet* pkt) {
4242
if (pkt->isRouteDirect() && pkt->getPayloadType() == PAYLOAD_TYPE_TRACE) {
43-
if (pkt->path_len < MAX_PATH_SIZE) {
43+
if (pkt->path_len < MAX_PATH_SIZE && pkt->payload_len >= 9) { // need trace_tag(4) + auth_code(4) + flags(1)
4444
uint8_t i = 0;
4545
uint32_t trace_tag;
4646
memcpy(&trace_tag, &pkt->payload[i], 4); i += 4;

0 commit comments

Comments
 (0)