Skip to content

Commit 1c05fbc

Browse files
committed
fix out-of-bounds read in TRACE packet hash matching
The TRACE handler uses isHashMatch() to compare this node's hash against an entry in the payload, but did not verify that enough bytes remain in the payload for the full hash comparison. The hash size is variable (1, 2, 4, or 8 bytes depending on path_sz), so when offset is close to the end of the payload, isHashMatch reads past the buffer boundary. Add a bounds check ensuring offset + hash_sz <= len before calling isHashMatch, preventing the over-read.
1 parent 06ab9f7 commit 1c05fbc

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

src/Mesh.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,10 @@ DispatcherAction Mesh::onRecvPacket(Packet* pkt) {
5151

5252
uint8_t len = pkt->payload_len - i;
5353
uint8_t offset = pkt->path_len << path_sz;
54+
uint8_t hash_sz = 1 << path_sz;
5455
if (offset >= len) { // TRACE has reached end of given path
5556
onTraceRecv(pkt, trace_tag, auth_code, flags, pkt->path, &pkt->payload[i], len);
56-
} else if (self_id.isHashMatch(&pkt->payload[i + offset], 1 << path_sz) && allowPacketForward(pkt) && !_tables->hasSeen(pkt)) {
57+
} else if (offset + hash_sz <= len && self_id.isHashMatch(&pkt->payload[i + offset], hash_sz) && allowPacketForward(pkt) && !_tables->hasSeen(pkt)) {
5758
// append SNR (Not hash!)
5859
pkt->path[pkt->path_len++] = (int8_t) (pkt->getSNR()*4);
5960

0 commit comments

Comments
 (0)