Browse Source

fix(repeater/sensor/room_server/secure_chat cli): permanent lockup without CR

The buffer-full branch writes the forced '\r' to command[sizeof-1], but the
line-complete check below tests command[len-1] (== sizeof-2 when the buffer
is full), so the line never completes: the read loop's condition
(len < sizeof-1) stays false forever and the CLI stops reading serial input
until reboot. Writing at [sizeof-1] also overwrites the string's NUL
terminator, so the next strlen() reads past the buffer (UB).

Write the '\r' at command[sizeof-2] instead — exactly the position the
completion check tests. The overflowed input is then processed as an
(unknown) command, the buffer resets, and the CLI keeps working.

Reproduced on hardware (T1000-E repeater): ~53 arrow-key presses in an
attached terminal (3-byte ESC[A escape sequences, 159 bytes with no CR)
filled the buffer and the CLI never accepted a command again until reboot.

The same copy-pasted pattern is fixed in simple_repeater, simple_sensor,
simple_room_server and simple_secure_chat.
pull/2978/head
Fedor Kallay 2 weeks ago
parent
commit
f76c46565a
  1. 2
      examples/simple_repeater/main.cpp
  2. 2
      examples/simple_room_server/main.cpp
  3. 2
      examples/simple_secure_chat/main.cpp
  4. 2
      examples/simple_sensor/main.cpp

2
examples/simple_repeater/main.cpp

@ -135,7 +135,7 @@ void loop() {
if (c == '\r') break;
}
if (len == sizeof(command)-1) { // command buffer full
command[sizeof(command)-1] = '\r';
command[sizeof(command)-2] = '\r'; // force-complete the line ([len-1] is tested below; [sizeof-1] would clobber the NUL and never match)
}
if (len > 0 && command[len - 1] == '\r') { // received complete line

2
examples/simple_room_server/main.cpp

@ -114,7 +114,7 @@ void loop() {
Serial.print(c);
}
if (len == sizeof(command)-1) { // command buffer full
command[sizeof(command)-1] = '\r';
command[sizeof(command)-2] = '\r'; // force-complete the line ([len-1] is tested below; [sizeof-1] would clobber the NUL and never match)
}
if (len > 0 && command[len - 1] == '\r') { // received complete line

2
examples/simple_secure_chat/main.cpp

@ -535,7 +535,7 @@ public:
Serial.print(c);
}
if (len == sizeof(command)-1) { // command buffer full
command[sizeof(command)-1] = '\r';
command[sizeof(command)-2] = '\r'; // force-complete the line ([len-1] is tested below; [sizeof-1] would clobber the NUL and never match)
}
if (len > 0 && command[len - 1] == '\r') { // received complete line

2
examples/simple_sensor/main.cpp

@ -131,7 +131,7 @@ void loop() {
Serial.print(c);
}
if (len == sizeof(command)-1) { // command buffer full
command[sizeof(command)-1] = '\r';
command[sizeof(command)-2] = '\r'; // force-complete the line ([len-1] is tested below; [sizeof-1] would clobber the NUL and never match)
}
if (len > 0 && command[len - 1] == '\r') { // received complete line

Loading…
Cancel
Save