From 90e25207c41010a5307beff7fd7a5a9e4be3653e Mon Sep 17 00:00:00 2001 From: Sean Kurtz Date: Fri, 27 Nov 2026 17:26:45 -0600 Subject: 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. --- src/exec.h | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (limited to 'src/exec.h') diff --git a/src/exec.h b/src/exec.h index 54f5b3e..e0db87b 100644 --- a/src/exec.h +++ b/src/exec.h @@ -1,6 +1,7 @@ /** * @file exec.h * @brief Command evaluation, redirection, jobs, traps and builtins. + * @note The unwind snapshot and the exception handler live in shell.h. */ #ifndef ZASH_EXEC_H #define ZASH_EXEC_H @@ -9,7 +10,6 @@ #include "ast.h" #include "sys.h" -#include "var.h" /* ---- evaluation (exec.c) --------------------------------------------- */ @@ -53,6 +53,7 @@ int run_input(unsigned flags); char *cmdsub_run(node *n, size_t *len); void exec_init(void); [[noreturn]] void shell_exec(char **argv, char **envp); +int shell_exec_try(char **argv, char **envp); /* ---- command table --------------------------------------------------- */ @@ -195,22 +196,10 @@ int builtin_bg(int argc, char **argv); char *node_text(const node *n); -/* ---- unwinding ------------------------------------------------------- */ - -/* Defined in parser.h. */ -typedef struct input_src input_src; - -/** - * @brief State that an exception handler must put back before continuing. +/* + * Unwinding: the unwind snapshot and exc_catch() live in shell.h, and the + * exception itself is raised by exc_raise() in util.c. */ -typedef struct unwind { - varscope *scope; - redirsave *redir; - input_src *input; -} unwind; - -void unwind_save(unwind *u); -void unwind_restore(const unwind *u); /* ---- traps (trap.c) -------------------------------------------------- */ @@ -223,6 +212,7 @@ void trap_run_err(void); void trap_init(void); void trap_poll(void); void trap_reset_child(void); +void trap_reset_exec(void); bool trap_has_exit(void); void trap_run_exit(void); const sigset_t *trap_spawn_defaults(void); -- cgit