Skip to content

F2: exec ordered redirect walk, fd-limit gate, stage stderr routing (Refs #2395, #2635, #2803, #2821) - #3144

Merged
caomengxuan666 merged 7 commits into
masterfrom
fix/F2-wave1
Nov 10, 2026
Merged

caomengxuan666 merged 7 commits into
masterfrom
fix/F2-wave1

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

组 F2(180 单令第一波):exec / 重定向 fd 面四单合一车道。

Refs #2395
Refs #2635
Refs #2803
Refs #2821

内容

本 PR 删除了什么

删除 execute_exec_spawn 中按 redirect_out / append / redirect_err / redirect_err_append 标量镜像互斥选一的全部 spawn 臂(由单一有序走线取代);旧 tail 本体以 execute_exec_spawn_tail 之名保留(镜像替换 + 捕获路由),仅去掉已被走线取代的 apply_no_output_builtin_redirects 一行。限额门提交无删除。

验证

  • 全组钉(基底 fail-first → 头侧):issue2395 茎 4 过 / 3 红 → 7/7;issue2635 茎 3 过 / 9 红 → 12/12;issue2803 茎 2 过 / 4 红 → 6/6;issue2821 茎 5 过 / 7 红 → 12/12。红名集恰为各单缺陷格、绿的恰为对照格。
  • lib 头/基底双边:1206/0/4 对 1206/0/4,失败名集双边皆空。
  • 邻茎 21 茎:20 茎头侧全绿;issue1025 茎唯一红为 /dev/tcp output face: plain > opens the connection twice and delivers zero bytes with a write error (output-side sibling of #1950) #1967 计数服务器 flake(基底三跑同为 pass/fail/pass,非本 PR 引入);issue826 茎头/基底同名集 3 过 / 9 红(基底既有环境红)。
  • RUSTFLAGS="-D warnings" 零警告;cargo fmt --check 全树通过。
  • GNU bash 5.3.20 探针矩阵(22 格 exec 矩阵 + 20 格链式 dup 矩阵 + 20 格限额矩阵)头侧逐格全同。

残余

草稿,待队长复核;勿合并、勿关单。

#2821)

GNU redir.c do_redirection_internal (redir.c:767+) walks the whole redirect list before shell_execve (execute_cmd.c:6126); every output target opens in list order and dups resolve against the bindings the walk has already made. The pin covers both list orders, append forms, numbered-fd targets, the failing-command diagnostic landing in the 2> file, and the single-redirect / dup-order / close / input controls. Fail-first on base 88047f5 per probe matrix (defect cells diverge from GNU bash 5.3.20, controls agree).
GNU redir.c TRANSLATE_REDIRECT (redir.c:803-870): [N]>&WORD with WORD all-digits is r_duplicating_output, WORD '-' is r_close_this, a non-numeric WORD at redirector 1 is r_err_and_out. The pin covers >&2, 1>&2, >&- (subshell form, write error EBADF), the >&word control, the failure diagnostic following fd 2, and the bare-exec boundary control. Fail-first on base 88047f5 per probe matrix.
GNU redir.c do_redirection_internal: the open succeeds (target created), the dup2 onto a redirector at/above the soft limit fails EBADF (redir.c r_output_direction); redirection_error (redir.c:149-176) renders <fd>: Bad file descriptor, dup entries name the source fd, close forms are exempt, and the failure lands at the entry's own list position. The pin covers bare exec (out/in/dup/positions), exec with a command, external, builtin and compound forms under ulimit -n 16, plus below-limit and close controls. Fail-first on base 88047f5 per probe matrix.
Refs #2821
Refs #2803
Refs #2395
Refs #2635

GNU do_redirection_internal (redir.c:767+) walks the command's whole
redirect list in parse order before exec_builtin (builtins/exec.def:231)
hands the bound descriptors to shell_execve (execute_cmd.c:6126). The
spawn consulted only the scalar mirror fields and returned from the
first matching arm, so at most one redirection ever applied (#2821),
and a `>&fd` / `>&-` mirror target was opened as a literal file name
(#2803: TRANSLATE_REDIRECT, redir.c:803-870, classifies the word —
digits are r_duplicating, `-` is r_close_this, a non-numeric word at
redirector 1 is r_err_and_out).

execute_exec_spawn now performs the ordered walk into an
ExecSpawnBinding composition (Ambient / File / Closed): every output
target opens at its list position, a dup resolves against the
bindings the walk has already made, fd >= 3 targets are created, and
the fd table's concrete endpoints (a pipeline stage's pre-bound
fd 2 File endpoint) resolve into bindings before composition — the
stage exec's stderr bytes and failure diagnostic now land in the
stage's own redirect file instead of leaking to the process stderr
(#2395; the temp-file residue face of that issue no longer reproduces
on this base, the carrier is anonymous from birth). The pure-ambient
case keeps the historical tail (image replacement + capture routing)
verbatim. Cross-slot ambient bindings resolve through a real dup of
the source object (Stdio::inherit is slot-relative), reusing the
external spawn's dup_process_handle, now pub(in crate::executor).
`>&-` binds a genuinely closed descriptor via the new
execute_with_child_stdio_closing (pre_exec close, the rubash#2378
realization), so the child reports its own write error.

The #2635 gates resident in this file land here too: the shared
redirect_fd_over_limit predicate over open_files_limit, the
bare-exec walk gate, and the spawn walk gate (reported through the
ExecuteError::IoError channel so the shell continues at status 1 —
a plain status reads as "the program ran" and ends the shell).

本提交删除了什么:删除 execute_exec_spawn 中按 redirect_out / append /
redirect_err / redirect_err_append 标量镜像互斥选一的全部 spawn 臂
(由单一有序走线取代);旧 tail 以 execute_exec_spawn_tail 之名保留
其镜像替换 + 捕获路由本体,仅去掉已被走线取代的
apply_no_output_builtin_redirects 一行。
Refs #2635

GNU's file arm runs redir_open first (the target is created), then
the dup2 onto a redirector at/above the RLIMIT_NOFILE soft limit
fails EBADF (redir.c r_output_direction: "dup2 failed? must be fd
limit issue"); redirection_error (redir.c:149-176) renders
`{fd}: Bad file descriptor` through the fd-2 binding established so
far, dup arms naming the SOURCE fd, the walk stops at the failing
entry, and close forms are exempt.

The shared redirect_fd_over_limit predicate (companion commit) now
also gates, each at its entry position after the entry's open side
effect: the OutputFdState walk (apply_ordered_output_redirects —
builtins, the external-command preflight, stage routing), the
compound output walk and the numbered input walk
(command_input_scope.rs), and the no-output builtin setup probe walk
(redirect_setup_open_error — the `true 16>f` face reaches none of the
other walks).

Reporting follows each walk's own protocol: the compound walks
return the failure through ExecuteError::IoError; the OutputFdState
walk records it through the state protocol (limit_gate_fail:
first_open_error for via-error states, silence for muted speculative
states, an fd-2 write otherwise) — an eager write there was reported
a second time by the compound bind on the function route (the
rubash#1844 shape). write_redirect_diagnostic_routed locates these
failures through a new fd-number fallback in
failing_open_redirect_index: a limit diagnostic names the fd number,
never a target path, so the target-head match could never position
it and misrouted the fail-first order (`16>f 2>e`).

本提交删除了什么:无删除(纯落门与路由定位扩展)。
@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 10, 2026 03:56
@caomengxuan666
caomengxuan666 marked this pull request as draft November 10, 2026 03:57
Conflict resolution (src/executor/trap_exec.rs only, 3 hunks): keep the PR's ordered exec-spawn walk; master's scalar-arm deltas land inside the walk structure — #1175 image replacement + capture-aware fd-1 routing are served by execute_exec_spawn_bound (both-stdio replacement attempt, capture branch) and execute_exec_spawn_tail verbatim; #3104's redirect_target_filesystem_path folding moves to the walk's three append opens (Output/Append, CombinedAppend, err-and-out append). Bare-exec walk: master's #2615 undo-save registration and the PR's #2635 limit gate both kept, registration first. Refs #2395, #2635, #2803, #2821.
@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 10, 2026 07:26
@caomengxuan666
caomengxuan666 merged commit d4f7d94 into master Nov 10, 2026
11 checks passed
caomengxuan666 added a commit that referenced this pull request Nov 10, 2026
…3262)

Refs #3089

## 问题

重定向目标词把一个含 IFS 空格的引号段与一个替换段拼起来时,rubash 误报 `ambiguous redirect`,而 GNU bash 按单字段语义建/读拼接出的文件。例:`> 'a b'$(printf '')`、`> "a b"$V`(V 空)、`>> 'a b c'${V}`(V 空)。

根因(GNU 锚点):GNU 的判词在 `redir.c:298 redirection_expand`——目标词展开后走 `subst.c:12397 word_list_split` 做 IFS 字段切分,字段数 ≠ 1 才报 ambiguous;引号段产出在 `subst.c:4773 quote_string` 经 `subst.c:11862 add_quoted_string` 得到保护,永不被切分。rubash 此前的判词对带标记的展开不做字段切分,而是对剥除载体后的文本做空白扫描,于是引号内的 IFS 空格被误判。

## 改法(机制级,无形状特判)

- `src/executor/expand_word.rs`:`expand_redirect_target` 对带标记的展开改走与参数管线同一个 IFS 字段切分器(`field_split_values_with_ifs`),以字段数作判词。信任条件二选一:(a) 标记展开带保护载体(经 markers.rs 的 pair-aware 助手 `contains_bare_sentinel` 判定,E400 对内成员是数据不是协议);(b) 原始词扫描证明不存在引号内 IFS 字符、也不存在引号内展开点——自定义 IFS 可使引号内空格成为普通数据、永不落载体(如 `IFS=:` 时空格非 IFS 字符),此时仿真标记本就无可保护,计数字段仍是 GNU 语义。信任且切分恰得一字段时,该字段即文件名——替换结果尾部的 IFS 空格按字段语义处理,不再残留在文件名中(`V='x '` 时 GNU 的单字段为 `a bx`)。
- `src/executor/redirection.rs`:`>(...)` 进程替换的同位点同步采用该判词(两行)。
- `scripts/marker-lint-allowlist.txt`:一处裸剥除按仓库既有形态登记为 owner restore chain——依据是 markers.rs `restore_bare_sentinels` 文档的不变量:带类型的 C0 字节永不以裸 C0 字符到达(恒以 raw-byte 标记对承载),故对 C0 载体的裸剥除不可能折入用户数据。其余两处裸字面消费已改走 pair-aware 助手。

## 本 PR 删除了什么

无删除。仅新增字段切分判词、两个模块内扫描助手与一条 allowlist 登记;被替代的文本扫描判词保留为无标记词的回落路径(其语义与基底一致,见基底对账)。

## 验证(Simular box,基底 `beab07dc`,按逐茎 test result 行与失败名集判读)

| 腿 | 基底 | 头 `62e46bb8` |
|---|---|---|
| 本钉 20 格 | 6 过 / 14 红(失败名集与立案登记逐名全等 = 误报面本身) | **20 过 / 0 红** |
| 邻茎 1769 / 1673 / 2999 / 1020 | — | 11/11、3/3、15/15、4/4 |
| lib 双边 | 1207 过 / 0 红 / 4 ignored | 1207 过 / 0 红 / 4 ignored(失败集双边皆 ∅) |
| `-D warnings --all-targets --keep-going` | rc=101,16 个存量测试面目标 | rc=101,错误集与基底逐项全等(同 16 个,零新增;`^error` 计数 32 = 32) |
| `cargo fmt -- --check` | — | rc=0 |
| marker-lint | 基底 rc=0 | rc=0(117 registry consts,265 allowlisted sites) |
| `cargo check --tests --target x86_64-unknown-linux-gnu` | — | rc=0 |

darwin/msvc 跨目标在验证箱上不可判(箱缺跨目标 C 工具链,基底同样失败),由 CI 判读:头提交 11 个 check-runs 全部收官(10 success + 1 skipped),三条 cross-target 腿皆 success。

队长复核(自有纯净克隆、四文件 sha256 双核、逐腿亲跑):八腿全过,判词见 `~/workspace/review-3262/CAPTAIN-VERIFY.md`。基底 lib 首跑两度遇箱上 OOM SIGKILL(无 test result 行,按 VOID 作废),重跑干净收官 1207/0/4。

## 门禁与漂移

- §0 硬门复核:PR #2968 头文件面恰 42 文件,不含 `expand_word.rs` / `redirection.rs`,本面 NOT gated。
- 主干漂移:补丁对已合入 PR #3144 的现行 master 做 `git apply --check` 通过(#3144 的 redirection.rs 六处与本补丁的判词条件零重叠)。

Refs #3089
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