Bound payload.bytes prints by payload.size (#11032)

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.
This commit is contained in:
Thomas Göttgens
2026-07-16 19:45:22 -05:00
committed by GitHub
co-authored by GitHub
parent 88f20d349a
commit 8ebdae9921
3 changed files with 6 additions and 6 deletions
+2 -2
View File
@@ -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) &&