# Regression tests for audit fixes across parser, redirection, builtins, # arithmetic, signals, test, printf, and options. # 1. Arithmetic uppercase digits for bases <= 36 (and case-sensitive 37..64) "$TSH" -c 'echo "base:$((16#FF)) $((36#Z)) $((64#z)) $((64#Z))"' # 2. Duplicating from a closed descriptor on an external command fails "$TSH" -c 'true 3>&- >&3' >/dev/null 2>/dev/null echo "dup-closed-ext:$?" "$TSH" -c '/bin/sh -c : 3>&- >&3' >/dev/null 2>/dev/null echo "dup-closed-spawn:$?" # 3. Parser: command substitution inside [[ ... ]], nested here-docs, # quoted braces inside "${...}", and rejecting "for x; in ..." "$TSH" -c '[[ -z $(echo hi >/dev/null) ]]; echo "cond-cmdsub:$?"' "$TSH" -c ' cat </dev/null inner INNER ) outer OUTER ' "$TSH" -c 'unset x; echo "qbrace:${x:-"a}b"}"' "$TSH" -c 'for x; in a b; do echo "$x"; done' 2>/dev/null echo "for-semi-in:$?" # 4. Environment deduplication for repeated prefix assignments "$TSH" -c 'X=1 X=2 /bin/sh -c "echo env:\$X"' "$TSH" -c 'X=1 X=2 env | grep "^X=" | wc -l | tr -d " "' # 5. PS4 expansion in xtrace (including command substitution without recursion) "$TSH" -c 'PS4="+ \$(echo tag): "; set -x; : ok' 2>&1 # 6. Pure subshell reports stdout write failure "$TSH" -c '( echo hi ) >&-' 2>/dev/null echo "subshell-werr:$?" # 7. Pipeline error unwind restores loop_depth "$TSH" -c ' for i in 1 2; do echo x | eval '\''echo "${unset?}"'\'' 2>/dev/null echo "pipe-loop:$i" done ' # 8. set +o omits startup-only options so eval "$(set +o)" succeeds "$TSH" -c 'saved=$(set +o); eval "$saved"; echo "set-plus-o:$?"' # 9. POSIX 1-4 argument test/[ rules and -t fd bounds "$TSH" -c ' [ "(" -f ")" ]; echo "t1:$?" [ "(" ! ")" ]; echo "t2:$?" [ -z -a -z ]; echo "t3:$?" [ -f -a -f ]; echo "t4:$?" [ ! "" -a "x" ]; echo "t5:$?" [ "(" ! "" ")" ]; echo "t6:$?" [ ! "(" -f ")" ]; echo "t7:$?" [ -t 4294967297 ]; echo "t8:$?" ' # 10. print -u fd upper bound and whence -p regular-file check "$TSH" -c 'print -u 4294967297 hi' 2>/dev/null echo "print-u-oob:$?" "$TSH" -c 'whence -p /tmp' >/dev/null 2>&1 echo "whence-dir:$?" # 11. printf overflow checks and NUL preservation in bare %b "$TSH" -c 'printf "%d\n" 999999999999999999999999999 >/dev/null 2>/dev/null; echo "pf-hi:$?"' "$TSH" -c 'printf "%d\n" -999999999999999999999999999 >/dev/null 2>/dev/null; echo "pf-lo:$?"' "$TSH" -c 'printf "%f\n" 1e99999 >/dev/null 2>/dev/null; echo "pf-dbl:$?"' "$TSH" -c 'printf "%b" "a\0000b" | wc -c | tr -d " "' # 12. Keywords, -- handling, unalias -- -a, kill --, read -t 0 "$TSH" -c 'command -v time select' "$TSH" -c 'eval -- echo "eval-dd:ok"' "$TSH" -c 'export -- Z_DD=ok; echo "export-dd:$Z_DD"' "$TSH" -c 'readonly -- Z_RO=ok; echo "ro-dd:$Z_RO"' "$TSH" -c 'umask -- 022; umask' "$TSH" -c 'alias keep=yes -a=no; unalias -- -a; alias keep' "$TSH" -c 'wait --; echo "wait-dd:$?"' "$TSH" -c 'kill -0 -- $$; echo "kill-dd:$?"' "$TSH" -c 'printf "ready\n" | { sleep 0.1; read -t 0 line; echo "read-t0:$?:$line"; }'