Validate advert payload length before parsing#1661
Open
weebl2000 wants to merge 1 commit intomeshcore-dev:devfrom
Open
Validate advert payload length before parsing#1661weebl2000 wants to merge 1 commit intomeshcore-dev:devfrom
weebl2000 wants to merge 1 commit intomeshcore-dev:devfrom
Conversation
The ADVERT handler copied pub_key, timestamp, and signature from the payload before checking whether payload_len was large enough to contain them. With a short payload, the memcpy operations read uninitialized data from within the payload buffer. Move the bounds check before any parsing so undersized adverts are rejected immediately. The minimum required is PUB_KEY_SIZE + 4 + SIGNATURE_SIZE (100 bytes).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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