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 authored and GitHub committed 2026-07-16 19:45:22 -05:00
1 parent 88f20d349a
commit 8ebdae9921
3 files changed
+6 -6

No files matched your search

+3 -3
View File
@@ -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();