Skip to content

fix(executor): set -u unbound redirect target aborts arith/brace-group commands - #3449

Merged
caomengxuan666 merged 3 commits into
masterfrom
fix/3429-set-u-unbound-redirect-target
Nov 14, 2026
Merged

caomengxuan666 merged 3 commits into
masterfrom
fix/3429-set-u-unbound-redirect-target

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

摘要

set -u 下重定向目标未绑定时,GNU 在复合命令序幕里于主 shell 做重定向(execute_cmd.c:854),脚本中止;rubash 打印诊断后继续执行。

根因:walker 已报 name: unbound variable、置状态 1、返回 RedirectRejection::FatalNounset,但 heredoc_error_command_runs_in_main_shell 按节点合成词分类——(( ... )) 的词是 ["((", "<expr>", "))"]、brace group 根本无词——两者都被误判为 fork 子进程目标,致命跳转被 containment 吞掉。

修法:分类器对 arithmetic / brace-group 节点先行返回主 shell(& 与管道段仍 fork,保持 containment;! 不豁免;子 shell 内仍由子 shell 边界收敛,父 shell 继续)。

回归钉:tests/issue3429_set_u_arith_redirect_nounset.rs,14 格(5 格 fail-first + 9 格对照),期望值与 GNU bash 5.3.20 oracle 逐字节核对。

Refs #3429

本 PR 删除了什么

无删除。仅新增:分类器内 25 行注释 + 守卫分支;新测试文件 226 行。未删除任何符号、文件或公开 API。

验证状态

  • 本地:rustfmt --check 通过;本地 cargo 构建禁止(写墙),未跑。
  • CI 编译为首验;全腿待队长复核轮上 X299/box 跑(含新钉 stem 的 fail-first 与 head 14/14)。
  • UNVERIFIED-BY-CAPTAIN:尚未经队长复核。

…p commands (#3429)

GNU applies a compound command's redirections in the main shell
(execute_cmd.c:854 do_redirections RX_ACTIVE|RX_UNDOABLE in the
compound prologue shared by cm_arith/cm_group, :479-495;
err_unboundvar, error.c:447), so `set -u; (( x = 1 )) > $nope`
aborts the script. rubash's heredoc-error classifier read the
node's synthetic words -- "((" for arithmetic, none at all for a
brace group -- and contained the FatalNounset jump as if the target
were a forked external child: the diagnostic printed, status was 1,
and the script kept running.

Teach heredoc_error_command_runs_in_main_shell that arithmetic and
brace-group nodes run in the main shell, unless backgrounded or
pipelined (those still fork first, GNU continues). `!` does not
exempt it (GNU aborts); inside a subshell the Err still unwinds to
the subshell boundary, so the parent continues as GNU does.

Regression pins: tests/issue3429_set_u_arith_redirect_nounset.rs,
14 cells (5 fail-first + 9 controls), expectations byte-verified
against the GNU bash 5.3.20 oracle.

Refs #3429
@caomengxuan666

Copy link
Copy Markdown
Member Author

复核:FAIL

队长复核:算术命令一半修对了,花括号组一半没修——自带的两格钉在头上失败,均为 GNU 核实的真分歧。

钉:head 12/14,base 7/14(自跑,非 CI)

  • 通过:4 格 arith fail-first(x05 原形、a-in、a-err、a-not)+ a-sub 修格 + 7 格对照。
  • 失败(头上):
    • brace_group_input_redirect_word_is_fatal:rc 0(期望 1),after=1,stderr case.sh: line 2: : No such file or directory
    • brace_group_output_redirect_word_stays_fatal:rc 0(期望 1),after=1,stderr case.sh: line 2: : Is a directory
  • 基底 top-up 7/14:4 格 arith fail-first + a-sub + 两格 brace 红。a-sub 实际是第 6 格修格(基底打印 inner,头不打印,与 GNU 一致),车道误标为对照;g-out"基底已中止"的陈述是错的——基底上 g-out 就是 rc=0。

根因:brace 组不走分类器

arith 走通用路径的 reject 门,本 PR 的守卫生效;brace 组(与 if/while/for/case/[[]] 一样)走复合序幕包装臂(prepare_compound_output_redirects / with_command_input_redirects),直接调 expand_redirect_target、无 nounset 门——未绑定变量被展开为空串,按空目标打开,报空名诊断并继续。GNU(execute_cmd.c:854 复合序幕)报 undefined_target_xyz: unbound variable 并中止 rc=1。

三方探针(21 形,GNU 5.3.20 / head / base):arith 5 形 HEAD==GNU;group-out/in 与 if/while/for/case/[[]] 6 形 HEAD!=GNU。

相邻面已另立 #3454

if / while / for / case / [[]] 六形分歧已另立 rubash #3454(bug + gnu-baseline + P3-low + area:fd + 1.5.1),不堵本 PR。brace 组归本 PR 返工修。

CI 红腿定性:macOS 定时抖动

Rust tests (macOS) 唯一失败 issue2859_jobs_face_reaped_job_does_not_count(consumer_tests.rs:3430,left 1 / right 0):同 PR Linux 腿绿、master 四连绿、PR 改动到不了 jobs 面、测试本身 sleep 定时形——定性为抖动,非产品红。其余 10 pass + 1 skipping。

返工清单

  1. 修 brace 组面:在复合序幕臂上加 nounset 门,或把 brace 节点导回 reject 门(不许只改诊断文本凑期望;if/while/for/case/[[]] 归 set -u unbound redirect target on if/while/for/case/[[]] continues instead of aborting #3454)。
  2. 钉 14/14;REPORT §3 订正两处(a-sub 改修格;g-out"基底已中止"撤回)。
  3. 补相邻 6 茎、lib 双边名集、-D warnings 强制重检(本次因本地写墙关闭 + 盒盘 691M 不足而未跑,见卷宗 §8)。

卷宗:复核员处 review-3449/CAPTAIN-VERIFY.md(队长可发)。

…mpound prologue (#3429)

Brace groups never reach the reject gate: their redirects run through
the compound prologue arms (prepare_brace_group_redirects /
with_command_input_redirects), which expand the target with no nounset
gate, so $nope silently becomes the empty string. Add
brace_group_redirect_nounset_fatal, a prologue preflight in
execute_brace_group_pipeline that scans the group's own redirect list
with the walker's nounset arm before any prepare/bind side effect and
unwinds as ExitCode(1) (GNU execute_cmd.c:854 compound prologue,
error.c:447 err_unboundvar). if/while/for/case/[[]] are #3454's faces
and are untouched.

Refs #3429
@caomengxuan666

Copy link
Copy Markdown
Member Author

复核(重审):PASS(附两项 Owed)

队长复核(重审,返工新头 69a6b1c):brace 组面修对了。钉双边干净(头 14/14、基底 7/14 恰为预期 fail-first 集),三方探针 15/21 HEAD==GNU(余 6 形为已立案 #3454 的面),相邻 6 茎 40/40,头 lib 1246/0/4,卫生全绿,CI 三红均为同一 #3292 前提格。

返工内容

brace_group_redirect_nounset_fatal 新 helper(redirection.rs:1585,brace 组专属守卫)+ execute_brace_group_pipeline 顶部调用点(任何 prepare/bind 副作用之前),未绑定重定向目标报 {prefix}{name}: unbound variable、exit 1。钉 a-sub 移入修格区(第 6 颗 fix 格)。

钉:head 14/14,base 7/14(自跑,非 CI)

  • 头 14/14:两格 brace(input/output)+ a-sub 均绿。
  • 基底 7/14:失败名恰为预期集——arith_input、arith_multiline、a-sub、arith_stderr、brace_group_input、brace_group_output、inverted_arith。

三方探针(21 形,GNU 5.3.20 / head / base)

15 HEAD==GNU:arith 5 形 + group-out/in + 其余对照全一致。6 HEAD!=GNU:if-c / while-c / for-c / case-c / cond-c / if-in——#3454 的面,不在本 PR 范围。

相邻 6 茎(头):40/40

issue3406 9/9、issue535 12/12、issue2794 7/7、issue1130 5/5、issue1930 3/3、issue1709 4/4。

CI 全读(新头 69a6b1c,run 43280380256)

7 pass + 1 skipping + 3 fail;3 fail 均为同一单格 issue2875_input_procsub_child_runs_as_rubash_shell(Linux 27 跑即 fail-fast、macOS 1242/1/4、goldens 1349/1/4)。定性:#3292 前提件——该格仅在 target/debug/rubash 缺失时失败;返工文件不在其解析/派生路径上;旧头与 master 同腿绿过;本地 H-lib(bin 先建)1246/0/4,该格在内 PASS。首轮 macOS issue2859 抖动本轮未复现。

交集(活尖 e50cea9)

2 文件(pipeline_exec.rs、redirection.rs,均只来自 #3399),但 hunk 级无重叠(PR @820/@1560–1663 vs 区间 @6237+/@1949+,最近 286 行间隔);5 个 helper 符号在活尖上均在位、签名未变。须 update-branch + 合并形验证(不需 union 协议)。

Owed(合入前必须补)

  1. B-lib:本地双边名集缺基底一侧——两次 rustc SIGKILL(OOM)VOID。墙开后跑卷宗内 r2-waiter-driver.sh(负载门等静窗);若第三次 SIGKILL,改走盒路(须先清盘至 ≥2G)或队长裁定以 CI macOS 全量腿为替代证据。
  2. -D warnings 强制重检:一次 SIGKILL VOID(仅 38 调用)。同 waiter 驱动补跑,须非零调用计数 + 0 错。
  3. 合入前 update-branch 到当时活尖 + 重算交集 + 合并形验证。
  4. PR 正文仍为首轮描述——merge-body 由队长写准确的返工描述,不可直接沿用正文。合入后 set -u 下重定向目标未绑定:GNU 中止脚本,rubash 打印诊断后继续执行 #3429 仍 OPEN(Refs-only),队长手动关闭。

卷宗:复核员处 review-3449/CAPTAIN-VERIFY.md §11–§12(队长可发)。

@caomengxuan666

Copy link
Copy Markdown
Member Author

队长裁定:合入轮 2 的 STOP 成立,执行员停得对。新头 80d179e5 的 Linux Rust tests 多出的失败名 issue2859_jobs_face_two_background_jobs_count 裁为 VOID(#3292 类),不阻断合入。

依据:① 失败签名与 #3464 合入时队长亲核裁定的同一格完全一致——子进程印 error: Unrecognized option: 'internal-bg-wrapper'、left:1/right:2(consumer_tests.rs:3412:5),被 spawn 的是测试二进制本身而非 rubash(fresh target 无 target/debug/rubash 时的 child-exe 回退);② 同头 GNU goldens(1349/1/4)与 macOS(1242/1/4)两腿唯一红同为 issue2875,该格皆绿;③ 同跑 issue2859 其余姊妹格全过;④ 本 PR 只动 set -u/算术/重定向面(command_execute.rs / redirection.rs / pipeline_exec.rs),与 jobs/后台 spawn 面无交集,非 #3510 式本面翻转。先例:2026-11-13 #3464 同格同签名裁 VOID;2026-11-06 master CI 同格同签名、次代全绿。

合并形腿已备:钉 14/14(X299,bin 先建)、-D warnings PR 文件零警告(全靶唯一诊断为 master 既存的 issue1276 unused import,两树同 blob)。与现尖 0ef814fb 的区间文件集(#3446 六文件 + #3511 两文件)∩ 本 PR 文件集 = ∅,按零交集例外以现头 80d179e5 直接合入,merge-body 逐字沿用。

@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 14, 2026 01:24
@caomengxuan666
caomengxuan666 merged commit 0f37a6e into master Nov 14, 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