Skip to content

Bound LCM protocol payloads#90

Open
mjc wants to merge 3 commits into
lukash:mainfrom
mjc:refloat-fix-lcm-protocol
Open

Bound LCM protocol payloads#90
mjc wants to merge 3 commits into
lukash:mainfrom
mjc:refloat-fix-lcm-protocol

Conversation

@mjc

@mjc mjc commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Bounds LCM protocol inputs before storing or forwarding them.

Changes

  • Copy poll names within the fixed name buffer and always terminate them.
  • Clamp the three brightness percentages to the schema-defined 0–100 range.
  • Clear one-shot payload state for every enabled light-control request, including malformed short requests.
  • Cap forwarded payloads at the fixed 64-byte storage capacity.
  • Remove the unreachable disabled-module branch from the enabled-only handler.

Behavior

Valid LCM traffic is unchanged. Oversized names and payloads stay within their fixed buffers, and a rejected short light-control request cannot leave an older payload queued for the next poll response.

I was able to cause a crash on the existing code with enough BTLE packets.

Copilot AI review requested due to automatic review settings July 14, 2026 20:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens the LCM (Light Control Module) protocol handling by bounding/normalizing incoming fields before storing them and before forwarding them back out, preventing out-of-bounds copies and invalid/stale payload behavior.

Changes:

  • Bound and null-terminate copied LCM name strings to avoid overruns.
  • Clamp brightness bytes to the protocol’s 0–100 range and cap stored/forwarded payload length to fixed capacity.
  • Reset per-request payload state and simplify the enabled-only light-control handler.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/lcm.c Outdated
@mjc
mjc marked this pull request as draft July 14, 2026 20:23
@mjc
mjc marked this pull request as ready for review July 14, 2026 20:39
@mjc
mjc marked this pull request as draft July 14, 2026 20:43
@mjc
mjc marked this pull request as ready for review July 14, 2026 20:43

@lukash lukash left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the changes in the two commits in this PR should ideally be split into 3 commits:

  • the simplification of the name copying code
  • limiting the brightnesses to max 100
  • handling the payload size overflow / clearing on short request

Comment thread src/lcm.c Outdated
@mjc
mjc force-pushed the refloat-fix-lcm-protocol branch from d9bf0b3 to dff2465 Compare July 20, 2026 16:42
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.

3 participants