summaryrefslogtreecommitdiffhomepage
path: root/tests/zash/arith-base.exp
Commit message (Collapse)AuthorAgeFilesLines
* fix(arith): parse base#digits without signed overflowSean Kurtz2 days1-0/+13
| | | | | | | | | | | | | | | | | | | | | | | `$((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).
* fix: the review findings, each with a regression testSean Kurtz3 days1-0/+5
Notes in notes/review-2026-11-27.md, one item per finding: 1. error unwinding read dead stack frames: the scope/redirection/input snapshot now lives in jmploc and is restored before the longjmp 2. `for` without `in` iterated over parameters that `set --` could free: the parameter block is reference-counted 3. `${4294967295}` and `${99999999999999999999}` indexed past the end: strtol, clamped to 1..$# 4. a trap stopped running after its own action raised: the re-entry flag is cleared before the action runs 5. `wait $pid` returned 127 once the job had been reaped 6. every external command failed with 127 when SIGCHLD was ignored at startup: dispositions are reset before the first child 7. a failed `exec` killed an interactive shell and skipped its EXIT trap: the shell returns 126/127, keeping the traps and restoring fds 0-9 8. `set -C` opened with O_TRUNC after a stat: O_EXCL, with the non-regular-file case worked around 9. a here-doc cut off by EOF used the delimiter as its body 10. `cd -- dir` failed and PWD came from the failed logical path 11. deep arithmetic recursion overflowed the stack: a depth check 12. the CSI type byte was converted twice on EBCDIC: guarded by ZASH_ASCII 13. a script that could not be read looked like an empty script: reported, with 2 at top level and 126/127 for the script; a directory is refused up front, because z/OS would otherwise read it as empty input Minors: `trap -p SIG`, `read -t` clamping and NaN, ksh `base#n` arithmetic, `${#@}`/`${#*}` as `$#`, `jobs` no longer mutating its table from a pipeline, the arena_grow contract, no pipe2 on macOS, and alias text copied into the input so redefining an alias while it is being read is safe.