Skip to content

Commit 181a54e

Browse files
authored
Merge pull request meshcore-dev#2532 from swaits/fix/trace-offset-widening
fix(mesh): widen TRACE offset to uint16 to avoid narrowing
2 parents 910b1be + 09a27a2 commit 181a54e

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

src/Mesh.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ DispatcherAction Mesh::onRecvPacket(Packet* pkt) {
5050
uint8_t path_sz = flags & 0x03; // NEW v1.11+: lower 2 bits is path hash size
5151

5252
uint8_t len = pkt->payload_len - i;
53-
uint8_t offset = pkt->path_len << path_sz;
53+
// path_len*entry_size can exceed 255 (path_len up to 63, entry_size up to 8);
54+
// a uint8_t offset would wrap and steer the isHashMatch() read to the wrong place.
55+
uint16_t offset = (uint16_t)pkt->path_len << path_sz;
5456
if (offset >= len) { // TRACE has reached end of given path
5557
onTraceRecv(pkt, trace_tag, auth_code, flags, pkt->path, &pkt->payload[i], len);
5658
} else if (self_id.isHashMatch(&pkt->payload[i + offset], 1 << path_sz) && allowPacketForward(pkt) && !_tables->hasSeen(pkt)) {

0 commit comments

Comments
 (0)