mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-10-29 17:54:14 +08:00
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.
This commit is contained in:
1 parent
28ea2184c2
commit
d562fd661e
1 file changed
+6
-1
+6
-1
@@ -166,10 +166,15 @@ uint8_t atoi_hex(uint8_t idx)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (h_idx == 8) {
|
||||||
|
h_idx = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// swap hex nibbles
|
// swap hex nibbles
|
||||||
val = (val >> 4) | (val << 4);
|
val = (val >> 4) | (val << 4);
|
||||||
|
|
||||||
if (c - '0' < 10) {
|
if ((uint8_t)(c - '0') < 10) {
|
||||||
val |= c - '0';
|
val |= c - '0';
|
||||||
} else {
|
} else {
|
||||||
c |= 0x20;
|
c |= 0x20;
|
||||||
|
|||||||
Reference in new issue
Block a user