Repository navigation
fix: Wave2a shell semantics batch - SIGQUIT policy ignore, -r entry via -s, readonly attr refusal, declare -na shape wins, ERR single-fire guard - #560
Merged
Conversation
…28+SIGQUIT (#526) kill -QUIT $$ in a non-interactive shell ended the whole rubash process with rc 131 and skipped the rest of the script. GNU bash ignores SIGQUIT in every shell: sig.c:102 initialize_signals -> sig.c:230 initialize_shell_signals sets SIGQUIT to SIG_IGN (sig.c:333) before the interactive-only SIGINT/SIGTERM installs, and trap.c:187-188 marks SIGQUIT SIG_SPECIAL so a trap reset returns to that ignore. WSL bash 5.3.0 oracle: 'kill -QUIT $$; echo survived=$?' prints survived=0 rc 0, also under 'bash -c' and after 'trap - QUIT'. The Windows mailbox dispatch treated an untrapped delivery as a killing default. Both dispatch sites now drop a QUIT with no trap action: run_pending_signal_traps (command boundary) and observe_signals_while_blocked (external-wait/sleep observer), keyed on a new platform SIGQUIT_NUMBER const beside SIGCHLD_NUMBER. Trapped QUIT still runs the action; untrapped SIGINT/SIGTERM keep their killing default (pinned by guard tests: rc 130/143). The unix kernel backend already encodes the same policy ignore, so its dispatch path is inert. Tests tests/issue526_sigquit_noninteractive_ignore.rs: kill-self via -c and -s, delivery while blocked in an external wait, trap-reset ignore, trapped action still fires, SIGINT/SIGTERM still fatal. 4/7 red on master, green here; GNU oracle WSL 5.3.0 2026-10-12.
… the argv scan (#527) 'bash -s -r' ran the stdin script the moment -s was seen, so the trailing -r was silently swallowed as a positional parameter: the shell came up unrestricted (flags=hBs, cd allowed) with $1=-r. The first entry path ('bash -r -s') already restricted, leaving the two documented call shapes disagreeing. GNU scans argv left to right: -s only marks read_from_stdin (shell.c parse_short_options), remaining options still apply, and non-option words after -s become positional parameters - a word that looks like a script path stays a positional too, stdin remains the source (verified WSL bash 5.3.0: 'bash -s /no/such/file' reads stdin, $1=the word; 'bash -s -r a b' -> flags=hrBs, $1=a $2=b). The -s arm now records read_from_stdin and the scan continues; non-option words collect as positionals (skipped as script files); after the loop the stdin script runs with those positionals, after the pending -c usage check so -c keeps precedence. -r -s, plain -s positionals, and -r -c are pinned against regressions. Tests tests/issue527_restricted_shell_entry.rs: -s -r restricts (cd refused rc1, flags=hrBs), -r -s unchanged, -s -r a b positionals, plain -s a b unrestricted, script-looking word after -s still reads stdin. 2/5 red on master, green here; GNU oracle WSL 5.3.0 2026-10-12.
'readonly R=1; declare -i R' silently turned R into -ir: the attribute pass had no readonly gate for the set direction, so third-party code could inject integer/array/assoc/case-mapping attributes onto a readonly variable and silently weaken the guarantee. GNU protects the attributes with the value: declare.def:893 refuses setting or clearing any of the invalid readonly attributes (integer/array/assoc/upper/lower/capcase, variables.h:126-128 valid/invalid_readonly_attrs) with one '<cmd>: <name>: readonly variable' diagnostic and a per-operand skip, declare.def:881 leaves an assignment word with nothing applied, and the refusal is all-or-nothing for mixed requests (-ix applies neither). The gate sits in declare's operand loop before assignment or attribute application, keyed on the existing readonly marks: invalid attrs in either direction, or an assignment paired with any modifiable attribute, error and skip the operand. Export, trace, re-setting readonly, +x and -p display stay allowed (rc 0, GNU-verified); +r removal, local -i, and plain assignments keep their existing single-diagnostic refusals. Tests tests/issue528_readonly_attr_change_refused.rs: -i/-a/-u/+i refusals with value and attributes preserved, -ir re-request, mixed -ix, assignment+attr single diagnostic, allowed export/trace/-r/-p paths, function-scope single diagnostic, and the pre-existing +r/local/assign guards. 7/15 red on master, green here; GNU oracle WSL 5.3.0 2026-10-12.
…together (#530) 'declare -na r' kept the nameref attribute ('declare -an r'), so every later assignment and expansion routed through nameref indirection instead of storing into the array - 'r=5' after the declaration even failed nameref value validation, and 'declare -na rv=tgt; tgt=zz' wrote through the reference. GNU treats nameref and array/assoc shapes as mutually exclusive with the shape winning: the nameref bit is lifted out of the set mask and cleared whenever the variable is or becomes an array (declare.def:962-981), an existing array conflicts with the -n request (declare.def:841), and the chain transform stays out of commands that toggle -n (declare.def:206). WSL bash 5.3.0 oracle: global -na/-nA is a silent drop (rc 0, 'declare -a r'); function scope still reports '<cmd>: <name>: reference variable cannot be an array' once while leaving the plain local array behind; an existing scalar moves to element 0; a valueless or chain-carrying nameref converts with its cell kept as element 0. The operand loop now clears the nameref mark for the command when -a/-A rides along - silent at global scope, one diagnostic at function scope - and the marks plus the assignment routing run with the lifted bit (nameref_marks). Existing arrays keep the declare.def:841 conflict with its proper message (the invalid-nameref-value check no longer masks it for array/assoc cells), a chain-carrying nameref under -na converts in place without following the chain, and the readonly, invalid-value and compound-assignment refusals keep their single-diagnostics. Tests tests/issue530_declare_na_drops_nameref.rs: global/function drops, -nA, scalar and nameref conversions, existing array/assoc conflicts, assignment routing before and after the declaration, invalid-value and readonly orderings, compound guard. 13/16 red on master, green here; GNU oracle WSL 5.3.0 2026-10-12.
… conforms
'trap 'echo E' ERR; { false; }; for i in 1; do false; done; case x in
x) false;; esac' printed E five times (each compound body re-adjudicated
its aggregate status after the inner failing command had already fired
the trap once). Master now prints E three times: the errexit body
adjudication from the P1 semantic batch gates BOTH consumers at the
post-execute_command site for if/while/until/for/case/select bodies, so
the ERR fire - whose GNU adjudication point is once per command in
execute_command_internal (execute_cmd.c:851 was_error_trap family, with
compound bodies handing their status up without a second look) - no
longer doubles.
No code change accompanies this commit: 3/8 of these tests are red on
the audited baseline 764b9dd (verified on a worktree build: the repro
prints E x5, the construct matrix carries the extra body fires, the
nested for-in-case double-fires) and 8/8 are green on this branch. The
tests pin the whole GNU-verified contract so the double fire cannot
return: one fire per failing body command; no fire for if/while/until
conditions, negated pipelines, redirected brace groups, or AND-OR left
arms; one fire for the final failing AND-OR arm; one fire for the failed
command-substitution assignment; function bodies silent without
errtrace but the failed call firing once (twice with set -E - body plus
call, GNU behavior); one fire on the set -e exit path.
GNU oracle WSL bash 5.3.0, 2026-10-12: every expected line sequence in
this file was captured from it; rubash matches byte for byte.
This was referenced Oct 12, 2026
[declare] declare -na/-nA 不丢弃 -n 属性:输出 declare -an r(GNU 丢弃 -n 得 declare -a;D3 与本 issue 同修)(P2)
#530
Closed
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.
Summary
Wave2a batch: five P2-medium shell behavior semantics bugs from the 443-divergence audit, each with a GNU oracle verification (WSL bash 5.3.0, 2026-10-12), an independent commit, and a RED-then-GREEN regression suite under
tests/issueNNN_*.rs. Behavior contracts are anchored on the vendored bash source (third_party/bash, bash-5.3-16); tests and comments describe behavior only.run_pending_signal_traps,observe_signals_while_blocked) drop a QUIT with no trap action; new platformSIGQUIT_NUMBERconst. Trapped QUIT still fires; SIGINT/SIGTERM stay fatal-ronly restricted when it precedes-s-sarm ran the stdin script immediately, so a trailing-rwas swallowed as a positional ($1=-r)-snow only marks read-from-stdin and the argv scan continues (shell.c parse_short_options model); non-option words after-sbecome positionals, never a script file; stdin run moves after the loop behind the-cusage checkdeclare -i Ron readonly R produced-irreadonly variablediagnostic; assignments paired with any attr apply nothing; export/trace/-r/+x/-p stay allowed (variables.h valid/invalid_readonly_attrs, declare.def refusal order)declare -nakept-nr=5failed nameref validation;declare -na rv=tgt; tgt=zzwrote through the reference)reference variable cannot be an arraydiagnostic at function scope with the plain local array still created; existing arrays keep the conflict diagnostic (invalid-value check no longer masks it for array cells); chain-carrying namerefs convert in place without chain-follow{ }/for/casebodiesTest plan
cargo test --no-fail-faston this branch vs pristineorigin/master(db3218a): failure sets identical name-by-name, 53 = 53, zero new failures, zero masked failures.cargo fmt --checkclean.