Skip to content

Comments

fix(commoncli): prevent command prefix overreads in handleCommand#1819

Open
robekl wants to merge 1 commit intomeshcore-dev:devfrom
robekl:fix/commoncli-safe-prefix-compare
Open

fix(commoncli): prevent command prefix overreads in handleCommand#1819
robekl wants to merge 1 commit intomeshcore-dev:devfrom
robekl:fix/commoncli-safe-prefix-compare

Conversation

@robekl
Copy link

@robekl robekl commented Feb 24, 2026

Summary

Fixes unsafe command-prefix parsing in CommonCLI::handleCommand that could read past the end of short input buffers.

Bug

handleCommand used fixed-length memcmp checks against command literals.
If the incoming command string was shorter than the compared length, the comparison could read beyond valid memory.

Trigger

Send a short or truncated CLI command that reaches a longer prefix check path (for example partial command tokens).

Impact

  • Undefined behavior from out-of-bounds reads
  • Potential crashes or hard faults on constrained targets
  • Incorrect command classification from reading unrelated memory

Fix

Replaced unsafe fixed-length memcmp usage with bounded prefix matching (prefixEq) that validates string length before comparing.

Replace fixed-length memcmp prefix checks with a bounded helper that first verifies the input has at least the required prefix length.

This preserves existing command matching behavior while avoiding out-of-bounds reads on short command strings.
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