Repository navigation
fix(executor): set -u unbound redirect target aborts compound commands (Refs #3454) - #3596
Merged
Merged
Conversation
…s (Refs #3454) GNU runs every compound's redirects in the main shell before dispatch (execute_cmd.c:854 do_redirections), so an unbound target word fails the expansion with `name: unbound variable` (error.c:447 err_unboundvar) and aborts the script. The prologue arms (prepare_compound_output_redirects / prepare_case_command_redirects / with_command_input_redirects / the [[ ]] bind / the word-sequence executors' apply_command_output_redirects) expand the target with no nounset gate: `$nope` became the empty string, the compound reported an empty-name diagnostic (`: Is a directory` / `: No such file or directory`), and the script continued. Generalize the #3429 brace gate into compound_redirect_nounset_fatal (brace + if/loop/for/case/select/[[ ]] kinds) and call it at the top of each *_with_redirects wrapper before any procsub materialization or create side effect; the fatal unwinds as ExitCode(1), aborting the script at top level exactly like the arith/brace fixes. The scan body is exposed as redirect_list_nounset_fatal so the word-sequence paths (execute_simple_loop, builtins::source::execute_simple_if — the `time while ... done` / `time if ...; fi` reparse doors, where the redirects live on the synthetic done/fi node) run the same check. Subshell `( )` and coproc are deliberately out of the node set: GNU runs their redirects in the spawned child — it reports the unbound name there but the parent continues — a different verdict family. Verified vs vendored GNU bash 5.3.20 script-file runs, byte-for-byte: if/while/until/for/arith-for/case/[[ ]]/select output and input forms all abort rc=1 with `name: unbound variable`; `time while ... done > \$nope` prints the diagnostic then the timing report then dies. 12-cell pin tests/issue3454_compound_redirect_nounset.rs (10 fail-first faces + bound-target and no-nounset controls). Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Member
Author
|
【WIN-AGENT-AUDIT】 机制核查:
腿(逐项):
F 点:无。 |
Member
Author
|
【队长终裁】PASS 核过审计报告(6886707451)+ CI 全表。钉 12/12,fail-first 2/10(10 个 unbound-abort 钉 base 全红、症状为 |
Member
Author
caomengxuan666
marked this pull request as ready for review
November 15, 2026 04:41
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
GNU runs every compound's redirects in the main shell before dispatch
(execute_cmd.c:854 do_redirections), so an unbound target word fails
the expansion with
name: unbound variable(error.c:447err_unboundvar) and aborts the script. The prologue arms
(prepare_compound_output_redirects / prepare_case_command_redirects /
with_command_input_redirects / the [[ ]] bind / the word-sequence
executors' apply_command_output_redirects) expand the target with no
nounset gate:
$nopebecame the empty string, the compound reportedan empty-name diagnostic (
: Is a directory/: No such file or directory), and the script continued.Generalize the #3429 brace gate into compound_redirect_nounset_fatal
(brace + if/loop/for/case/select/[[ ]] kinds) and call it at the top of
each *_with_redirects wrapper before any procsub materialization or
create side effect; the fatal unwinds as ExitCode(1), aborting the
script at top level exactly like the arith/brace fixes. The scan body
is exposed as redirect_list_nounset_fatal so the word-sequence paths
(execute_simple_loop, builtins::source::execute_simple_if — the
time while ... done/time if ...; fireparse doors, where theredirects live on the synthetic done/fi node) run the same check.
Subshell
( )and coproc are deliberately out of the node set: GNUruns their redirects in the spawned child — it reports the unbound
name there but the parent continues — a different verdict family.
Verified vs vendored GNU bash 5.3.20 script-file runs, byte-for-byte:
if/while/until/for/arith-for/case/[[ ]]/select output and input forms
all abort rc=1 with
name: unbound variable;time while ... done > \$nopeprints the diagnostic then the timing report then dies.12-cell pin tests/issue3454_compound_redirect_nounset.rs (10 fail-first
faces + bound-target and no-nounset controls).
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>