From 1521be38034eeef4474f39df8257a907f9bae267 Mon Sep 17 00:00:00 2001 From: MarekZegare4 Date: Sun, 14 Jun 2026 12:53:40 +0200 Subject: [PATCH] fix(trail): check read() return for header bytes in readFrom/exportGpxFromFile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mirrors the Waypoint::readFrom() hardening — reject a truncated trail snapshot instead of proceeding with garbage header fields. Consistency with the waypoint store's persistence path. Co-Authored-By: Claude Sonnet 4.6 --- examples/companion_radio/Trail.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/companion_radio/Trail.h b/examples/companion_radio/Trail.h index 9639a5b5..9646b9f4 100644 --- a/examples/companion_radio/Trail.h +++ b/examples/companion_radio/Trail.h @@ -201,10 +201,10 @@ public: uint8_t ver = 0, res = 0; uint16_t cnt = 0; uint32_t accum = 0; - file.read(&ver, 1); - file.read(&res, 1); - file.read((uint8_t*)&cnt, sizeof(cnt)); - file.read((uint8_t*)&accum, sizeof(accum)); + if (file.read(&ver, 1) != 1) return false; + if (file.read(&res, 1) != 1) return false; + if (file.read((uint8_t*)&cnt, sizeof(cnt)) != (int)sizeof(cnt)) return false; + if (file.read((uint8_t*)&accum, sizeof(accum)) != (int)sizeof(accum)) return false; if (ver != SAVE_VERSION || cnt > CAPACITY) return false; if (_active) { _active = false; @@ -344,10 +344,10 @@ public: uint8_t ver = 0, res = 0; uint16_t cnt = 0; uint32_t accum = 0; - file.read(&ver, 1); - file.read(&res, 1); - file.read((uint8_t*)&cnt, sizeof(cnt)); - file.read((uint8_t*)&accum, sizeof(accum)); + if (file.read(&ver, 1) != 1) return 0; + if (file.read(&res, 1) != 1) return 0; + if (file.read((uint8_t*)&cnt, sizeof(cnt)) != (int)sizeof(cnt)) return 0; + if (file.read((uint8_t*)&accum, sizeof(accum)) != (int)sizeof(accum)) return 0; if (ver != SAVE_VERSION || cnt > CAPACITY) return 0; size_t total = gpxHeader(out);