Add minimum payload_len check for TRACE packet parsing #1663
+1
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Severity: Medium
Summary
The TRACE packet handler reads 9 bytes from the payload —
trace_tag(4),auth_code(4), andflags(1) — before any length validation. The Dispatcher layer does not enforce a minimumpayload_lenfor any packet type, so a TRACE packet withpayload_len = 0reaches this code and reads stale data from the payload buffer.Additionally,
uint8_t len = pkt->payload_len - i(wherei = 9) underflows whenpayload_len < 9, wrapping to ~247. This can cause the subsequentoffset >= lencheck to pass or fail incorrectly, leading to unintended trace forwarding or hash matching against garbage data.Who can exploit this: any node on the mesh — TRACE packets are unauthenticated and direct-routed.
What it takes: a single crafted short TRACE packet.
What users might see
Incorrect trace routing, spurious trace forwarding, or (less likely) nodes processing traces they shouldn't. No crash — reads stay within the 184-byte payload buffer.
Fix
Add
pkt->payload_len >= 9to the existing guard condition so undersized TRACE packets are silently dropped before any field parsing.Test plan
Heltec_v3_companion_radio_ble