summaryrefslogtreecommitdiffhomepage
path: root/scripts
diff options
context:
space:
mode:
authorSean Kurtz <seankurtz75@gmail.com>2026-11-28 00:23:42 -0600
committerSean Kurtz <seankurtz75@gmail.com>2026-11-28 00:23:42 -0600
commitec1cd3eb8e1aa177329f25d134f372d3e999d4a4 (patch)
tree75bae4df72bdb54da467dc5b404caa49c0781e0e /scripts
parent9cdf5f548dc8e1d5c6315b304819bf0fd60f802f (diff)
downloadzash-ec1cd3eb8e1aa177329f25d134f372d3e999d4a4.tar.gz
fix(arith): parse base#digits without signed overflow
`$((99999999999999999999#1))` multiplied its way through INT_MAX: UBSan reports "signed integer overflow" at the base loop in parse_based(), and in a release build the resulting base is whatever the wrap gave. The base is now built with a bound (anything over 64 is "bad number base" at once) and the digits are read by hand against ksh's digit set, so `16#0x10`, `16# f`, `2#2` and `16#` stay errors instead of relying on strtoumax()'s quirks. The digit set is a string looked up with strchr(), not arithmetic on character codes: the letters are not contiguous in EBCDIC, and the same source has to work on both sides. That also makes bases 37 to 64 work, as they do in ksh: `$((64#z))` is 35, `64#_` is 63, `64#@` is 62. Values still wrap at UINTMAX_MAX, which is what the old code did for everything else, so a literal that does not fit is still "bad number". Verified: before the change, zash-asan reports src/arith.c:270 signed integer overflow for the huge base and rejects 64#z; after it, the new tests pass under ASan+UBSan on Linux. The EBCDIC build is untested here (the mapping is a string constant, so it does not depend on the charset).
Diffstat (limited to 'scripts')
0 files changed, 0 insertions, 0 deletions