Skip to content

Validate command headers before dispatch#89

Merged
lukash merged 2 commits into
lukash:mainfrom
mjc:refloat-fix-command-length
Jul 19, 2026
Merged

Validate command headers before dispatch#89
lukash merged 2 commits into
lukash:mainfrom
mjc:refloat-fix-command-length

Conversation

@mjc

@mjc mjc commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Reject truncated app-command payloads before reading their two-byte header.

The VESC app-data callback can receive zero- or one-byte payloads. The old handler read buffer[0] and buffer[1] before checking the length, producing an out-of-bounds read. The old length check then returned for len < 2, so these packets did not reach command dispatch.

The guard now runs before either header byte is accessed.

I was able to eventually get a device reboot from this but it took a lot of packets.

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

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 VESC app-command receive path by validating the minimum payload length before reading the two-byte command header, preventing out-of-bounds reads on truncated (0–1 byte) packets.

Changes:

  • Move the len < 2 guard to run before accessing buffer[0]/buffer[1].
  • Keep existing command dispatch behavior unchanged for valid packets while rejecting too-short payloads early.

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

Comment thread src/main.c Outdated
Comment thread src/main.c Outdated
@lukash
lukash merged commit 9191f65 into lukash:main Jul 19, 2026
1 check passed
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