Bound payload.bytes prints by payload.size#11032
Conversation
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.
📝 WalkthroughWalkthroughPayload debug, CSV, echo, and text-mode output now print packet payloads using their explicit sizes rather than relying on null termination. ChangesPayload output formatting
Estimated code review effort: 1 (Trivial) | ~5 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/modules/RangeTestModule.cpp`:
- Around line 307-311: Update the CSV row-writing sequence around the payload
formatter so rx_rssi remains on the same row as the payload, matching the
header’s column order. Escape every embedded double quote in p.payload before
emitting it, while preserving the existing bounded payload handling, and write
exactly one record terminator only after the RSSI column.
In `@src/modules/SerialModule.cpp`:
- Line 399: Update the self-echo output in SerialModule to use byte-oriented
serialPrint->write with p.payload.bytes and p.payload.size instead of
printf("%.*s"), preserving embedded NUL bytes and matching the default serial
path.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: d2de6406-e7db-488f-9cd1-68a453226261
📒 Files selected for processing (3)
src/mesh/Router.cppsrc/modules/RangeTestModule.cppsrc/modules/SerialModule.cpp
⚡ Try this PR in the Web FlasherNote Building this pull request… the flash button, badges and supported-board |
decoded.payload.bytesis a fixed 233-byte protobuf bytes field and is notNUL-terminated. A few sites print it with a plain
"%s", which reads until it finds aNUL; a full-length payload with no NUL byte makes that read run off the end of the field.
Fixed to
"%.*s"bounded bypayload.size, which is the formSerialModulealready uses for the rawwrite(bytes, size)case a few lines up.Live sites:
RangeTestModule.cppappendFile()- writes received text to the range-test CSVSerialModule.cpp- PROTO/TEXTMSG serial output of received messagesThe same change is applied to three currently commented-out debug lines
(
RangeTestModulex2,Router.cppcompression block) so the pattern stays correct ifthey are ever re-enabled; those are not live today.
Swept the tree for every other
payload.bytesused as a C string. The rest are alreadysafe:
pb_decode/pb_encode/memcpywith an explicit size,strnlen(payload, 219)(under the 233-byte field) in
MessageStore, apayload.size-bounded alert-scan loop inMessageRenderer, an explicit clamped length in the InkHUD store path, and astrncasecmpbounded by a 54-byte local buffer inDropzoneModule. Many call sitesalready use the
"%.*s"form; this brings the stragglers in line.No unit test: the two live sites are inline writes to a Stream and to the filesystem, so a
targeted repro needs serial/FS mocking for what is a mechanical format-string bound with no
behavior change for valid input. The coverage env builds with ASan, which guards the
broader decode paths the suite already exercises.
Summary by CodeRabbit