Skip to content

Validate buffer length before reading fields in Packet::readFrom#1666

Open
weebl2000 wants to merge 2 commits intomeshcore-dev:devfrom
weebl2000:fix/packet-readfrom-bounds
Open

Validate buffer length before reading fields in Packet::readFrom#1666
weebl2000 wants to merge 2 commits intomeshcore-dev:devfrom
weebl2000:fix/packet-readfrom-bounds

Conversation

@weebl2000
Copy link
Contributor

Severity: Low

Summary

Packet::readFrom reads the header byte, transport codes (4 bytes if present), and path_len from the source buffer before performing any length validation. With a short input (e.g. len = 0), these reads go past the end of the source buffer.

Unlike the main radio receive path (which parses packets inline in Dispatcher::checkRecv with proper bounds checking), readFrom is used by bridge interfaces (RS232, ESP-NOW) and importContact (flash blob storage). A corrupted blob or malformed bridge frame could trigger the over-read.

Fix

Add upfront length checks:

  • Minimum 2 bytes overall (header + path_len)
  • Transport codes require 4 additional bytes
  • Path bytes plus at least 1 byte of payload must fit before proceeding

Test plan

  • Bridge packet reception still works (RS232, ESP-NOW)
  • Contact import/export still works
  • Short/corrupt inputs return false without reading past the buffer
  • Build tested on Heltec_v3_companion_radio_ble

readFrom reads the header byte, transport codes (4 bytes), and
path_len from the source buffer before any length validation. With a
short input, these reads go past the end of the buffer.

Add upfront length checks: minimum 2 bytes overall, transport codes
require 4 additional bytes, and path must fit before the remaining
payload.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant