Repository navigation
fix(executor): trap set -u in arithmetic array subscripts on write (#639) - #654
Merged
Merged
Conversation
) set -u; a[k]=v silently stored with status 0. GNU evaluates every subscript through evalexp -> expr_streval, whose unbound block aborts on both read and write (expr.c:1190-1216). The write-path subscript evaluator was missing the nounset prologue its arithmetic command/expansion siblings have; added it, silenced the five downstream operand-expected diagnostics on the flag, and routed the abort with the context-owned fatal status at every write consumer (element write, compound rewrite x2, assign-default, unset x2, wait-var x2). The trap is FORCE_EOF, not DISCARD: a distinct nounset_force_eof cell rides the shared abandon vehicle, consumed at the ast abandon point which recomputes the context status there (127 at -c, 1 in script), with every pending-clearing boundary clearing the cell alongside. Compound m=([k]=v) diverts to Err(ExitCode(fatal)) at the apply_shell_assignment failure mapping. No memo changes (frames are per-word-expansion). Verification: new 25-case GNU differential 10/25 -> 25/25; -c matrix all 127 with abandon (script mode 1; unset-on-missing stays silent per GNU); new tests/issue639_nounset_subscript.rs (11 tests); lib 584 + focused suites green; full serial failure-set gate vs bc258ad identical (NEW=0; 1/1 part_080 coproc flake passing in isolation both sides); niubash A/B 49=49 apart from the known load-flaky timing test (passes+fails back-to-back on one tree).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix(executor): trap
set -uin arithmetic array subscripts on the write path (#639)What
set -u; a[k]=vsilently stored with status 0. GNU evaluates everysubscript through
evalexp→expr_streval, whose unbound block aborts onboth read and write (
expr.c:1190-1216). The write-path subscriptevaluator was missing the nounset prologue its arithmetic
command/expansion siblings have.
Fix
eval_indexed_subscript_expression: the same nounset prologue aseval_arithmetic_command_value/eval_arithmetic_expansion_value(scan + single message + flag). Assoc keys bypass arithmetic entirely,
so
declare -A A; A[k]=vstays silent by construction. No memo changes:the subscript memo frames are per-word-expansion, so a store without
nounset cannot mask a later trap and vice versa (probed both toggle
directions).
report_indexed_subscript_errorsites stay silent when the flagis set (message already printed once).
raise_nounset_subscript_abort(consumes the flag so a caught abortnever poisons later commands): abandon with the context-owned fatal
status at the element-write arm, both compound rewrite sites, the
assign-default path, both unset arms, and both
wait-var write paths.nounset_force_eofcellrides the shared abandon vehicle, and the ast abandon point recomputes
the context status there (127 at
-c, 1 in script) so no intermediateexit-code write can downgrade it. Every boundary that clears the pending
flag clears the cell alongside (subshell/comsub/external/function
resets); subshell containment verified (
( set -u; a[k]=v ); echo afterprints
after, rc 0).m=([k]=v)needed one more hop: its failure returns throughapply_shell_assignment, whose generic failure maps toExpansionFailure(1)— the nounset cell now diverts toErr(ExitCode(fatal))first (mirrors the POSIX arm directly below it).Verification
Covers write/append/compound/declare/unset-existing traps, read
controls, assoc negatives, both toggle directions, function/subshell/
eval/redirect/default/
-vshapes. (Local GNU is 5.3.20, not the WSL5.3.0 oracle — every rule cited from vendored
expr.c, and the oneknown version-sensitive number, the for-header status, is recorded.)
-cmatrix: write/append/compound/declare/unset-existing all abandonwith rc 127; script mode rc 1;
unseton a missing array stays silentwith rc 0 (GNU evaluates subscripts only when the array exists —
probed).
tests/issue639_nounset_subscript.rs(11 tests,-cbyte assertsincl. the 127 status).
compound-quote, 536); full serial failure-set gate vs
bc258ad:target sets identical (248=248 ok, 26=26 failed, NEW=0), test-level 1
NEW / 1 DISAPPEARED both in the known-nondeterministic
part_080coproc family (both pass in isolation on both trees); niubash product
A/B failure sets identical (49=49) apart from the known load-flaky 50x
timing-ratio test (passes and fails back-to-back on the same tree).
Out of scope (tracked separately)
evalcontainment of the abort (eval does not contain the assignment DISCARD jump (eval 'a[-2]=q' ends the whole script) #637 — open, with recon):evaldoesnot catch yet, so the abort propagates out. No behavior claimed there.
[@]/[*]message wording (compound a+=( [@]=q ) reports an arithmetic error instead of "cannot assign to non-numeric index" #636 — open, with recon).GNU owners:
expr.c:1190-1216 expr_streval,error.c:447 err_unboundvar,arrayfunc.c:1356 array_expand_index,shell.c:1471vs:1477(FORCE_EOF vs DISCARD catch),
subst.c:11169(assignment-error jump).