Skip to content

fix(executor): contain the assignment DISCARD jump at the eval boundary (#637) - #657

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/issue637-eval-discard
Oct 16, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/issue637-eval-discard

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

fix(executor): contain the assignment DISCARD jump at the eval boundary (#637)

What

eval 'a=(p); a[-2]=q; echo IN'; echo AFTER ended the whole script with
status 1. GNU catches DISCARD at the eval boundary
(evalstring.c:365,422-442) — eval returns failure and the caller
continues. Rubash absorbed ExpansionFailure there but let the
evalerror_pending abort escape.

Fix

  • New evalerror_subscript_pending class marker, armed alongside the
    abort at the bad-subscript sites (plain a[-2]=q / a[]=v / [@] /
    unresolvable-negative in element assignment, compound-negative tail).
    Arithmetic and nounset failures never arm it, so they keep escaping.
  • execute_eval_source absorbs exactly this class on Ok: clears
    pending/line/marker, returns Ok (eval fails, caller continues). A
    real Err propagates untouched (and drops a leaked mark so an outer
    eval cannot mistake it for its own string).
  • The eval'd top list runs at a recorded depth
    (eval_list_depth: Cell<Option<usize>>, save/restored per eval
    nesting): nested aborts unwind silently everywhere EXCEPT that frame,
    where GNU's parse_and_execute loops per line — a later line still runs
    and eval returns its status. Function/loop bodies inside eval run
    deeper and keep unwinding.
  • The marker is consumed at the ast abandon point and cleared at every
    pending-clearing boundary (subshell/comsub/external/function resets),
    same discipline as the nounset cell — except inside an eval string,
    whose boundary owns absorption.
  • Exit code is deliberately left alone at absorb: it already holds the
    last status (a later line that ran fine yields eval rc 0).

Verification

Out of scope

GNU owners: evalstring.c:365,422-442 (DISCARD catch),
subst.c:11169-11176 bash_variable_assignment_error,
arrayfunc.c:1388-1390 (arith escape, deliberately untouched).

…ry (#637)

eval 'a=(p); a[-2]=q; echo IN'; echo AFTER ended the whole script with
status 1. GNU catches DISCARD at the eval boundary
(evalstring.c:365,422-442): eval returns failure and the caller
continues. Rubash absorbed ExpansionFailure there but let the
evalerror_pending abort escape.

A distinct evalerror_subscript_pending cell marks bad-subscript aborts
(armed at the element-write sites + compound tail); the eval boundary
absorbs exactly this class on Ok, leaving the exit status to the last
command run (GNU parse_and_execute loop: a later line that ran fine
yields eval rc 0). Arithmetic and nounset failures never arm it and keep
escaping; a real Err propagates untouched (dropping a leaked mark). The
eval'd top list runs at a recorded depth so nested aborts fall through
to line-skip logic instead of unwinding silently; deeper function/loop
bodies keep unwinding. Consumed at abandon (outside eval strings) and
cleared at every pending-clearing boundary.

Verification: new 20-case GNU differential 9/20 -> 20/20; new
tests/issue637_eval_discard.rs (9 tests); all other batteries unchanged
(nounset 25/25, atstar 14/15 with #635 case, indexed 49/50 with #651,
assoc 50/50); focused suites green; full serial failure-set gate vs
ea9c18e identical targets (NEW=0/DISAPPEARED=0; 3/1 part_080 coproc
flake passing in isolation); niubash A/B identical apart from the known
load-flaky timing test (passes in isolation on the failing leg).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant