From 8ab2c68f25e66c46a8a57f47a60e5d4d0a22cc37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 16 Jul 2026 22:02:58 +0200 Subject: [PATCH] Bound payload.bytes prints by payload.size decoded.payload.bytes is a 233-byte protobuf field that is not NUL-terminated. Printing it with a plain "%s" reads until a NUL, which for a full-length payload with no NUL runs past the field. Use "%.*s" with payload.size, matching the write form already used a few lines up in SerialModule. Live sites: RangeTestModule appendFile, SerialModule text output. The same fix is applied to the commented-out debug lines in RangeTestModule and Router so the pattern is consistent if they are re-enabled. --- src/mesh/Router.cpp | 2 +- src/modules/RangeTestModule.cpp | 6 +++--- src/modules/SerialModule.cpp | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/mesh/Router.cpp b/src/mesh/Router.cpp index 7ae78cbb162..9a3776386d0 100644 --- a/src/mesh/Router.cpp +++ b/src/mesh/Router.cpp @@ -753,7 +753,7 @@ meshtastic_Routing_Error perhapsEncode(meshtastic_MeshPacket *p) LOG_DEBUG("Original length - %d ", p->decoded.payload.size); LOG_DEBUG("Compressed length - %d ", compressed_len); - LOG_DEBUG("Original message - %s ", p->decoded.payload.bytes); + LOG_DEBUG("Original message - %.*s ", (int)p->decoded.payload.size, p->decoded.payload.bytes); // If the compressed length is greater than or equal to the original size, don't use the compressed form if (compressed_len >= p->decoded.payload.size) { diff --git a/src/modules/RangeTestModule.cpp b/src/modules/RangeTestModule.cpp index 57001919d39..7e6b5fcf773 100644 --- a/src/modules/RangeTestModule.cpp +++ b/src/modules/RangeTestModule.cpp @@ -154,7 +154,7 @@ ProcessMessage RangeTestModuleRadio::handleReceived(const meshtastic_MeshPacket NodeInfoLite *n = nodeDB->getMeshNode(getFrom(&mp)); LOG_DEBUG("-----------------------------------------"); - LOG_DEBUG("p.payload.bytes \"%s\"", p.payload.bytes); + LOG_DEBUG("p.payload.bytes \"%.*s\"", (int)p.payload.size, p.payload.bytes); LOG_DEBUG("p.payload.size %d", p.payload.size); LOG_DEBUG("---- Received Packet:"); LOG_DEBUG("mp.from %d", mp.from); @@ -192,7 +192,7 @@ bool RangeTestModuleRadio::appendFile(const meshtastic_MeshPacket &mp) meshtastic_NodeInfoLite *n = nodeDB->getMeshNode(getFrom(&mp)); /* LOG_DEBUG("-----------------------------------------"); - LOG_DEBUG("p.payload.bytes \"%s\"", p.payload.bytes); + LOG_DEBUG("p.payload.bytes \"%.*s\"", (int)p.payload.size, p.payload.bytes); LOG_DEBUG("p.payload.size %d", p.payload.size); LOG_DEBUG("---- Received Packet:"); LOG_DEBUG("mp.from %d", mp.from); @@ -307,7 +307,7 @@ bool RangeTestModuleRadio::appendFile(const meshtastic_MeshPacket &mp) fileToAppend.printf("%d,", mp.hop_limit); // Packet Hop Limit // TODO: If quotes are found in the payload, it has to be escaped. - fileToAppend.printf("\"%s\"\n", p.payload.bytes); + fileToAppend.printf("\"%.*s\"\n", (int)p.payload.size, p.payload.bytes); fileToAppend.printf("%i,", mp.rx_rssi); // RX RSSI fileToAppend.flush(); diff --git a/src/modules/SerialModule.cpp b/src/modules/SerialModule.cpp index 23e8e9790a6..48e482927e6 100644 --- a/src/modules/SerialModule.cpp +++ b/src/modules/SerialModule.cpp @@ -396,7 +396,7 @@ ProcessMessage SerialModuleRadio::handleReceived(const meshtastic_MeshPacket &mp lastRxID = mp.id; // LOG_DEBUG("* * Message came this device"); // serialPrint->println("* * Message came this device"); - serialPrint->printf("%s", p.payload.bytes); + serialPrint->printf("%.*s", (int)p.payload.size, p.payload.bytes); } } } else { @@ -408,7 +408,7 @@ ProcessMessage SerialModuleRadio::handleReceived(const meshtastic_MeshPacket &mp meshtastic_NodeInfoLite *node = nodeDB->getMeshNode(getFrom(&mp)); const char *sender = nodeInfoLiteHasUser(node) ? node->short_name : "???"; serialPrint->println(); - serialPrint->printf("%s: %s", sender, p.payload.bytes); + serialPrint->printf("%s: %.*s", sender, (int)p.payload.size, p.payload.bytes); serialPrint->println(); } else if ((moduleConfig.serial.mode == meshtastic_ModuleConfig_SerialConfig_Serial_Mode_NMEA || moduleConfig.serial.mode == meshtastic_ModuleConfig_SerialConfig_Serial_Mode_CALTOPO) &&