Harden framing and exact I/O paths for partial read/write safety (plus related parser and stats improvements)#1905
Open
robekl wants to merge 1 commit intomeshcore-dev:devfrom
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
This PR focuses on the primary reliability issue for embedded environments: partial reads/writes and unchecked I/O causing stream/file corruption, parse desync, or silent persistence failures.
The core change introduces and applies stricter exact-I/O behavior, then extends related hardening in packet framing/parsing and serial bridge ingress/egress paths.
Problem
On constrained devices and links, reads/writes can be partial. Existing code paths had several risks:
These issues can lead to:
Primary Changes (Partial Read/Write Handling)
1) Added strict exact file I/O helper
src/helpers/CheckedIO.hchecked_io::readExact(...)with loop-until-complete or failchecked_io::writeExact(...)with loop-until-complete or failreadValue/writeValue2) Applied checked exact I/O to persistence paths
src/helpers/ClientACL.cppsrc/helpers/IdentityStore.cppsrc/helpers/CommonCLI.cpp3) Hardened WiFi framed I/O for partial read/write failures
src/helpers/esp32/SerialWifiInterface.cppsrc/helpers/esp32/SerialWifiInterface.hsrc/helpers/BaseSerialInterface.hgetDropCount()API (returns 0 by default)Related / Derived Hardening Changes
Packet framing/parsing correctness
src/Packet.h,src/Packet.cppPacket::readFromnow takessize_tsrc/Dispatcher.cppPacket::readFromsrc/helpers/BaseChatMesh.cppreadFromreturn and releases packet on failureBridge/radio ingress bounds
src/helpers/bridges/RS232Bridge.cppMAX_TRANS_UNITreadFrom(..., size_t)src/helpers/esp32/ESPNOWRadio.cpprecvRawCrypto input guard
src/Utils.cppStats surface for WiFi drops (no protocol framing changes)
src/helpers/StatsFormatHelper.hstats-radioJSON now includeswifi_dropssrc/helpers/CommonCLI.hgetSerialDropCount()callback hook (default 0)examples/simple_sensor/SensorMesh.cppexamples/simple_room_server/MyMesh.cppexamples/simple_repeater/MyMesh.cppdocs/cli_commands.md