From d562fd661e1c8ad2d56ba0ba9d18316084299321 Mon Sep 17 00:00:00 2001 From: d00f <8052722+DrDoof@users.noreply.github.com> Date: Thu, 15 Oct 2026 20:38:55 +0200 Subject: [PATCH] cmd_parser: stop atoi_hex() at eight digits and at non-hex characters hexvalue[] holds four bytes, but atoi_hex() stored every digit it was given, so a ninth digit was written past the array into whatever follows it in xdata. More than eight digits now return 0, as any bad input does. c - '0' < 10 is computed as an int, so characters below '0' such as '-', '.' or '/' passed as digits and "-1" came out as 0xdf. The difference is now taken as uint8_t, so they are rejected. --- cmd_parser.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cmd_parser.c b/cmd_parser.c index 9e226dbf..2902fbcf 100644 --- a/cmd_parser.c +++ b/cmd_parser.c @@ -166,10 +166,15 @@ uint8_t atoi_hex(uint8_t idx) break; } + if (h_idx == 8) { + h_idx = 0; + break; + } + // swap hex nibbles val = (val >> 4) | (val << 4); - if (c - '0' < 10) { + if ((uint8_t)(c - '0') < 10) { val |= c - '0'; } else { c |= 0x20;