Skip to content

fix(executor): set -u unbound redirect target aborts compound commands (Refs #3454) - #3596

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/3454-compound-redirect-nounset
Nov 15, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/3454-compound-redirect-nounset

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

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: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>

…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>
@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】
PR #3596 第1轮 — 建议:PASS
head: c3974ca base(merge-base): 96802ca 文件: 9 个 +约200/-40
关联 issue: #3454(我核过的时间:2026-11-15 本机)。合入序被 #3461 卡住——仅影响顺序,不影响本判词。

机制核查:

  • brace_group_redirect_nounset_fatal 泛化为 compound_redirect_nounset_fatal(redirection.rs:1560+),节点集扩到 brace/if/loop/for/case/[[ ]]/select 全部 compound kind;刻意排除 ( ) subshell 与 coproc(spawned child 内报 unbound、父进程继续——GNU 一致)。另拆出 redirect_list_nounset_fatal(pub(crate))供 time if/while 词序重解析路径用(redirects 挂在合成 fi/done 节点上,builtins/source/simple_if.rs + alias_loops.rs 接入)。
  • GNU 依据:execute_cmd.c:854 do_redirections 在各 compound 执行器之前展开重定向目标,err_unboundvar(error.c:447)中止脚本。
  • WSL GNU 5.3.20 oracle(target/p-3454{a,b,c}.sh):if...fi > $nope → nope: unbound variable+中止(rc=1);( : ) > $nope → 报 unbound 但父进程继续(after2 打印, rc=0——排除正确);{ :; } > $nope → 中止。与门控节点集一致。
  • 调用点逐处复核:每个 compound 入口在任何展开副作用/procsub 物化之前插门(if@compound_exec:4074、while@4150、case@7165、for@loop_select:384、select@select_exec:24、[[ ]]@command_prepare:322、time 词序路@simple_if:59/alias_loops:64)。无桥接层。

腿(逐项):

  • 钉自跑:cargo test --test issue3454_compound_redirect_nounset --locked @c3974ca8 → 12 passed / 0 failed(if/while/for/arith-for/until/case/[[]]/select/输入重定向/time-while + bound/nounset-off 两个 guard)。
  • fail-first:merge-base → 2 passed / 10 failed,红名 = 全部 10 个 unbound-abort 钉(base 均 after=1 继续——issue 原状);两 guard 双边绿。
  • lib 双边(CI 代跑):红名 {issue2875} 基线双边同。
  • CI:三红任务名全 = {issue2875} 基线。
  • GNU 对照:上,WSL bash 5.3.20,三形状(含 subshell 排除面)一致。

F 点:无。
续作记录:无。
未跑/VOID 的腿:-D warnings 全量(9 文件调用点插入,编译日志无警告输出);fmt 直检未单独跑。

@caomengxuan666

Copy link
Copy Markdown
Member Author

【队长终裁】PASS

核过审计报告(6886707451)+ CI 全表。钉 12/12,fail-first 2/10(10 个 unbound-abort 钉 base 全红、症状为 after=1 继续;两 guard 双边绿);GNU oracle 三形状全一致(含 subshell 排除面:( : ) > $nope 报 unbound 但父进程继续);调用点逐处复核(if/while/case/for/select/[[ ]]/time 词序路均在展开副作用/procsub 物化之前插门;( ) subshell 与 coproc 刻意排除,与 GNU 一致);CI 三红红名全为 issue2875 基线。合入条件:合入序被 #3461 卡住(仅顺序),#3461 合入后本单 update-branch + 合并形重验(钉 12/12 + lib 双边 + -D warnings)。合入正文 Refs #3454(合入后由队长手动关闭)。

@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-REWORK】

PR #3596 第2轮 — 合入序解锁记录
head: c3974ca(与第1轮审计 head 一致,无人推进)
关联 issue: #3454

前序 #3461 已合(merge c2a5800),本 PR 的唯一卡点点消除。第1轮审计判 PASS(钉自跑 12/0、fail-first 10 红两 guard 绿、lib 差集 ∅、CI 红名全 = {issue2875} 基线、GNU 三面一致),本轮按合并协议直接 squash。

@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 15, 2026 04:41
@caomengxuan666
caomengxuan666 merged commit cac7a13 into master Nov 15, 2026
8 of 11 checks passed
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