Repository navigation
Conversation
readFrom() read the header, transport codes, path_len and up to 64 path bytes before looking at 'len', so a truncated packet made it read past the end of the source buffer (the packet was rejected afterwards, but the over-read had already happened). Check 'len' before each read. Add host tests (test_packet) for truncated header, transport codes and path, invalid path_len, and valid round trips. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Contributor
|
See also #3521, which covers this case and various others. |
This branch has not been deployed
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.
Problem
Packet::readFrom()reads the header, the 4 transport-code bytes,path_lenand up to 64 path bytesbefore it looks at
len. The only length check (i >= len) ran after those reads, so a truncatedpacket made it read up to ~70 bytes past the end of
src. The packet was still rejected afterwards,but the out-of-bounds read had already happened.
There is no out-of-bounds write: the
path/payloadcopies are already bounded byisValidPathLen()and
sizeof(payload). On the radio path the receive buffer is large, so this is mostly benign there;it matters for callers that pass a tightly sized buffer (bridges, network/serial transports, host builds).
Change
Check
lenbefore each read:len >= 2(header +path_len)len >= 6when the route type has transport codesi + path_byte_len < lenbefore copying the path (also guarantees at least one payload byte,replacing the old
i >= lencheck)No change to the packet format or to the result for valid packets.
Tests
New host test
test/test_packet(pio test -e native -f test_packet): empty/header-only input,truncated transport codes, path longer than input, path with no payload, reserved
path_len,valid flood and transport packets, and a
writeTo()/readFrom()round trip. Inputs use exactly-sizedheap buffers so a sanitizer build flags any read past
len.Full
pio test -e native: 54 passed, 1 suite skipped (test_companion_node_prefs, unrelated).