Validate advert payload length before parsing #1661
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: Low
Summary
The ADVERT packet handler copies the public key (32 bytes), timestamp (4 bytes), and signature (64 bytes) from the payload before checking whether
payload_lenis large enough to contain them. With a short payload, the memcpy operations read uninitialized data from within the payload buffer array.The reads stay within the 184-byte
payload[]array so this is not a true out-of-bounds access, but the parsed values (pub_key, timestamp, signature) contain garbage. The bounds check at line 251 catches it before any side-effects occur (no routing, no signature verification passes with garbage), but the ordering is sloppy and could become a real bug if the buffer layout changes.Fix
Move the bounds check before any parsing. Undersized adverts are now rejected immediately with a debug log, before any memcpy operations execute.
Test plan
Heltec_v3_companion_radio_ble