From c39d68ddb362c5afbce8616e5f89c61d98a96f87 Mon Sep 17 00:00:00 2001 From: Mark Rose Date: Fri, 27 Nov 2026 15:45:18 -0600 Subject: [PATCH] Sensor CLI: 'io' must match the whole word and parse its argument memcmp(command, "io ", 2) accepted every command starting with "io", and a write whose argument had no hex digits passed an uninitialised value to board.setGpio(). Co-Authored-By: Claude Mythos 5.2 --- examples/simple_sensor/SensorMesh.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/examples/simple_sensor/SensorMesh.cpp b/examples/simple_sensor/SensorMesh.cpp index 8a68381ae..c3aeffb48 100644 --- a/examples/simple_sensor/SensorMesh.cpp +++ b/examples/simple_sensor/SensorMesh.cpp @@ -497,21 +497,26 @@ void SensorMesh::handleCommand(ClientInfo* from, uint32_t sender_timestamp, char Serial.printf("\n"); } reply[0] = 0; - } else if (memcmp(command, "io ", 2) == 0) { // io {value}: write, io: read + } else if (strcmp(command, "io") == 0 || memcmp(command, "io ", 3) == 0) { // io {value}: write, io: read if (command[2] == ' ') { // it's a write - uint32_t val; + uint32_t val = 0; uint32_t g = board.getGpio(); + bool ok; if (command[3] == 'r') { // reset bits - sscanf(&command[4], "%x", &val); - val = g & ~val; + ok = sscanf(&command[4], "%x", &val) == 1; + val = g & ~val; } else if (command[3] == 's') { // set bits - sscanf(&command[4], "%x", &val); - val |= g; + ok = sscanf(&command[4], "%x", &val) == 1; + val |= g; } else if (command[3] == 't') { // toggle bits - sscanf(&command[4], "%x", &val); - val ^= g; + ok = sscanf(&command[4], "%x", &val) == 1; + val ^= g; } else { // set value - sscanf(&command[3], "%x", &val); + ok = sscanf(&command[3], "%x", &val) == 1; + } + if (!ok) { + strcpy(reply, "Err - bad params"); + return; } board.setGpio(val); }