Skip to content

Commit b9c4542

Browse files
caveman99ndoo
andcommitted
Bail out on a zero-sized buffer and cast err for %ld
snprintf writes nothing at all when bufsz is 0, not even a terminator, so the checksum helper would run strchr over whatever the buffer already held. Return before touching it. int32_t is not long on every target, so cast before formatting with %ld. Co-Authored-By: Andrew Yong <me@ndoo.sg>
1 parent eea9024 commit b9c4542

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

src/gps/NMEAWPL.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ static uint32_t nmeaChecksum(const char *buf)
4040

4141
uint32_t printWPL(char *buf, size_t bufsz, const meshtastic_PositionLite &pos, const char *name, bool isCaltopoMode)
4242
{
43+
if (bufsz == 0)
44+
return 0;
45+
4346
GeoCoord geoCoord(pos.latitude_i, pos.longitude_i, pos.altitude);
4447
char type = isCaltopoMode ? 'P' : 'N';
4548
uint32_t len = snprintf(buf, bufsz, "\r\n$G%cWPL,%02d%07.4f,%c,%03d%07.4f,%c,%s", type, geoCoord.getDMSLatDeg(),
@@ -54,6 +57,9 @@ uint32_t printWPL(char *buf, size_t bufsz, const meshtastic_PositionLite &pos, c
5457

5558
uint32_t printWPL(char *buf, size_t bufsz, const meshtastic_Position &pos, const char *name, bool isCaltopoMode)
5659
{
60+
if (bufsz == 0)
61+
return 0;
62+
5763
GeoCoord geoCoord(pos.latitude_i, pos.longitude_i, pos.altitude);
5864
char type = isCaltopoMode ? 'P' : 'N';
5965
uint32_t len = snprintf(buf, bufsz, "$G%cWPL,%02d%07.4f,%c,%03d%07.4f,%c,%s", type, geoCoord.getDMSLatDeg(),
@@ -89,6 +95,9 @@ uint32_t printWPL(char *buf, size_t bufsz, const meshtastic_Position &pos, const
8995

9096
uint32_t printGGA(char *buf, size_t bufsz, const meshtastic_Position &pos)
9197
{
98+
if (bufsz == 0)
99+
return 0;
100+
92101
GeoCoord geoCoord(pos.latitude_i, pos.longitude_i, pos.altitude);
93102
time_t timestamp = pos.timestamp;
94103

src/platform/stm32wl/STM32_LittleFS.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ const char *dbg_strerr_lfs(int32_t err)
273273

274274
default:
275275
static char errcode[13];
276-
snprintf(errcode, sizeof(errcode), "%ld", err);
276+
snprintf(errcode, sizeof(errcode), "%ld", (long)err);
277277
return errcode;
278278
}
279279

0 commit comments

Comments
 (0)