Skip to content

[HIGH] Ensure command buffers stay NUL-terminated to prevent overflow - #3395

Merged
ripplebiz merged 1 commit into
meshcore-dev:devfrom
jbrazio:fix/serial-command-clamp
Sep 11, 2026
Merged

[HIGH] Ensure command buffers stay NUL-terminated to prevent overflow#3395
ripplebiz merged 1 commit into
meshcore-dev:devfrom
jbrazio:fix/serial-command-clamp

Conversation

@jbrazio

@jbrazio jbrazio commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

The CLI loops in the examples size the command buffer with strlen() and keep appending to it. When the buffer fills, the old code wrote '\r' over the final byte, the one holding the NUL. From then on strlen() can walk past the buffer and the append loop indexes past the end.

Clamps len at the top of each pass and, when the buffer is full, places the end-of-line marker at len-2 so the final byte stays NUL. Applied to companion_radio, simple_repeater, simple_room_server, simple_secure_chat and simple_sensor.

The corruption usually showed up as random reboots on TX, most visible on 433MHz boards. Serial lines left floating pick up RF noise, and that noise fills the command buffer. Most boards are affected; the Heltec v3 just shows it more often.

The serial command buffers must stay NUL-terminated within their
bounds: if they ever aren't, strlen() can return >= sizeof(command)
and the read loop would index past the buffer. Additionally, a full
buffer now becomes a completed line (end-of-line marker placed
inside the buffer, NUL terminator kept) instead of overwriting the
terminator and silently corrupting the buffer for the next pass.

Applies to the serial CLI readers of the repeater, room server,
sensor and secure chat examples, and to the CLI rescue reader of
the companion example.
@h0lad

h0lad commented Sep 10, 2026

Copy link
Copy Markdown

Can confirm this issue and your bugfix.

We worked and debugged on same problem in different worlds at the same time :-) I'll need a lot of Portuguese sun to heal the trauma I suffered from analyzing it... it took many days.

This bug crashes my HT-CT62 repeater every 24-36h.

RAK3172 is less affected but the implementation shares the same code.

My Analysis: #3397

@ripplebiz
ripplebiz merged commit 0984111 into meshcore-dev:dev Sep 11, 2026
14 of 15 checks passed
@jbrazio
jbrazio deleted the fix/serial-command-clamp branch September 11, 2026 10:23
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