Re: [PATCH 1/3] kstrtox: introduce a safer version of memparse()

From: Qu Wenruo
Date: Wed Dec 27 2023 - 15:29:59 EST




On 2023/12/27 23:56, David Disseldorp wrote:
On Sat, 23 Dec 2023 20:28:05 +1030, Qu Wenruo wrote:

+ s = _parse_integer_fixup_radix(s, &base);
+ rv = _parse_integer(s, base, &value);
+ if (rv & KSTRTOX_OVERFLOW)
+ return -ERANGE;
+ if (rv == 0)
+ return -EINVAL;

I was playing around with your unit tests and noticed that "0xG" didn't
reach the expected rv == 0 -> -EINVAL above. It seems that
_parse_integer_fixup_radix() should handle 0x<non hex> differently, or
at least step past any autodetected '0' octal prefix.

Yes, that's also the problem I hit, but I'm not 100% sure if changing
_parse_integer_fixup_radix() is safe for other call sites thus I didn't
put such test case here.

My initial failure cases includes things like "0x" which would still
return 0 is already a warning sign.

Thanks,
Qu

Cheers, David