summaryrefslogtreecommitdiffhomepage
path: root/tests/linux
diff options
context:
space:
mode:
authorSean Kurtz <seankurtz75@gmail.com>2026-11-27 17:26:45 -0600
committerSean Kurtz <seankurtz75@gmail.com>2026-11-27 17:26:45 -0600
commit90e25207c41010a5307beff7fd7a5a9e4be3653e (patch)
treef257cce6d24590e5e41af525dcb85931ab39002d /tests/linux
parente8f3a27f981f2d13cf6ccc9f9a08bebe3d44ac60 (diff)
downloadzash-90e25207c41010a5307beff7fd7a5a9e4be3653e.tar.gz
fix: the review findings, each with a regression test
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.
Diffstat (limited to 'tests/linux')
-rw-r--r--tests/linux/i-exec-fail.exp12
-rw-r--r--tests/linux/i-exec-fail.sh17
-rw-r--r--tests/linux/i-unwind.exp7
-rw-r--r--tests/linux/i-unwind.sh15
4 files changed, 51 insertions, 0 deletions
diff --git a/tests/linux/i-exec-fail.exp b/tests/linux/i-exec-fail.exp
new file mode 100644
index 0000000..0dd7a13
--- /dev/null
+++ b/tests/linux/i-exec-fail.exp
@@ -0,0 +1,12 @@
+$ exec /nonexistent/cmd
+SHELL: /nonexistent/cmd: not found
+$ echo "rc=$?"
+rc=127
+$ exec /nonexistent/cmd > out.txt
+SHELL: /nonexistent/cmd: not found
+$ echo after
+after
+$ wc -c < out.txt
+0
+$ exit
+[status 0]
diff --git a/tests/linux/i-exec-fail.sh b/tests/linux/i-exec-fail.sh
new file mode 100644
index 0000000..db4cfc5
--- /dev/null
+++ b/tests/linux/i-exec-fail.sh
@@ -0,0 +1,17 @@
+# Interactive: a failed `exec` must not end the shell, must report status 127,
+# and must leave the shell's own descriptors alone after a redirection.
+command -v python3 >/dev/null 2>&1 || exit 77
+PS1='$ ' ENV='' HISTFILE='' \
+ python3 "$TESTS/tools/ptydrive.py" "$TSH" -i <<'END'
+send exec /nonexistent/cmd\r
+expect $
+send echo "rc=$?"\r
+expect rc=127
+send exec /nonexistent/cmd > out.txt\r
+expect $
+send echo after\r
+expect after
+send wc -c < out.txt\r
+expect 0
+send exit\r
+END
diff --git a/tests/linux/i-unwind.exp b/tests/linux/i-unwind.exp
new file mode 100644
index 0000000..f765da1
--- /dev/null
+++ b/tests/linux/i-unwind.exp
@@ -0,0 +1,7 @@
+$ f() { x=1 let "1/0" 2>/dev/null; }; { f; } >/dev/null
+$ echo survived
+survived
+$ echo "x=[$x]"
+x=[]
+$ exit
+[status 0]
diff --git a/tests/linux/i-unwind.sh b/tests/linux/i-unwind.sh
new file mode 100644
index 0000000..ed79a5d
--- /dev/null
+++ b/tests/linux/i-unwind.sh
@@ -0,0 +1,15 @@
+# Interactive: a command killed by an error inside a group redirection leaves
+# the prompt usable and stdout back on the terminal. The frames the error
+# jumped over held the redirection and the variable scope, so a restore that
+# walks them after the jump reads dead stack.
+command -v python3 >/dev/null 2>&1 || exit 77
+PS1='$ ' ENV='' HISTFILE='' \
+ python3 "$TESTS/tools/ptydrive.py" "$TSH" -i <<'END'
+send f() { x=1 let "1/0" 2>/dev/null; }; { f; } >/dev/null\r
+expect $
+send echo survived\r
+expect survived
+send echo "x=[$x]"\r
+expect x=[]
+send exit\r
+END