security: replace sprintf/strcpy with bounds-checked variants #9601
+26
−20
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
sprintfcalls withsnprintfacross multiple modulesstrcpycalls withstrncpy+ null terminationChanges by file:
DetectionSensorModule.cppsprintfinto 40-byte buf with user-configurable sensor name (up to 20 bytes)snprintf(msg, 40, ...)DropzoneModule.cppsprintfwithowner.short_name/long_namefrom mesh + weather datasnprintf(buf, sizeof(buf), ...)KeyVerificationModule.cppsprintfinto ClientNotification message bufferssnprintf(cn->message, sizeof(cn->message), ...)NodeDB.cppsprintfwarning message with remotelong_name(40 bytes)snprintf(cn->message, sizeof(cn->message), ...)RedirectablePrint.cppstrcpyinto 384-bytelogRecord.messageand 32-bytelogRecord.sourcestrncpy+ null terminationFSCommon.cppstrcpyfilesystem path into 228-bytefileInfo.file_namestrncpy+ null terminationNodeInfoModule.cppstrcpynode ID into 16-byteu.idstrncpy+ null terminationBackground
MeshCore's security audit flagged widespread
sprintf/strcpyusage without bounds checking. The same pattern exists in Meshtastic. While most buffers are sized adequately for typical data, user-configurable fields (sensor names, node names) and mesh-received data (owner names) could exceed buffer limits.Test plan
tbeambuild succeeds