Skip to content

fix(executor): gate heredoc/herestring redirectors at/above the RLIMIT_NOFILE soft limit (Refs #3195) - #3576

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/3195-heredoc-fd-limit-gate
Nov 14, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/3195-heredoc-fd-limit-gate

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

ulimit -n 16 下,heredoc / herestring 的显式重定向符 ≥ 软限时,GNU 在绑定位置报 16: Bad file descriptor 且不绑定该 fd;rubash 接受并正常绑定,命令照常读到 heredoc 内容(#2635 同族残余:限额门落在五条既有走线,heredoc/herestring 条目不经其中任何一条)。

本 PR 按 #2635 同口径在四处落门(+83/−2,4 文件 + 19 测回归钉):

  • src/executor/builtin_redirects.rs(no-output 内建 setup 走线):HereDoc/HereString 条目在自家 list 位置过门,过限返回 {fd}: Bad file descriptor。
  • src/executor/command_input_scope.rs(有序 walk):同上口径,过限 Err(ExecuteError::IoError(...))。
  • src/executor/redirection.rs(list_binds 有序 walk):过限走本 walk 的失败协议(limit_gate_fail),命名 redirector;failing_open_redirect_index 并入 HereDoc/HereString 的 file-arm 分支,使限额失败诊断可路由定位。
  • src/executor/trap_exec.rs([bug] RLIMIT_NOFILE 软限内重定向目标 fd ≥ 限额时不报错(GNU: Bad file descriptor, rc 1) #2635 门的 gate 探针):HereDoc/HereString 并入 file-arm,redirect_fd_over_limit(gate_fd).then_some(gate_fd),无文件预开(body 物化即 open)。

限下路径逐点核对与旧代码等价(builtin_redirects 旧 fall-through 对该 kind 同样 continue;其余三门只在过限时触发)。

GNU semantics

redir.c:heredoc body 先物化(here_document_to_fd,redir.c:1072),再 dup2 到 redirector(redir.c:1120,≥ 软限时 EBADF);redirection_error(redir.c:135,EBADF 命名在 redir.c:166-175)默认命名 redirector。失败落在条目自己的 list 位置,此前副作用保留、此后条目不执行;{var} 形除外(fcntl F_DUPFD 分配,恒在限下)。

Verification (Linux, bin-first, -j 1; base = master 8b48c164, head = this branch)

  • Pin tests/issue3195_heredoc_fd_limit.rs(19 测):头 19/19;基底 fail-first 2/19(仅两对照过:fd 15 绑定、{var} 限下分配)。
  • 相邻父面钉 issue2635_redirect_fd_limit:头 12/12。
  • 三向探针(probes/{probe1,cases1-4}.sh,GNU 5.3.20 vs 基底 vs 头,归一化后):GNU vs 头全 MATCH,仅 hd-multi-below(exec 14<<A 15<<B 限下双 heredoc,第一条绑定丢失)一处差——基底同症既有缺陷,与限额门无关,合入后另立跟进单(钉未覆盖该形)。
  • Lib 双边:头 1247/0/4 = 基底 1247/0/4,失败名集差 ∅。
  • RUSTFLAGS="-D warnings":全量腿欠(未在最终头上跑过,合入前由复核轮补跑);REPORT 所记调用数未实测,不作证据。
  • 卫生:git diff --check 与 rustfmt --edition 2021 --check(5 RS 文件)干净。

What this PR deletes

  • 未删产品代码路径。本 PR 只新增限额门:替换的只是 heredoc/herestring 条目在过限时"静默绑定"的旧行为(该行为与 GNU 有差,见上);限下行为逐点核对不变。删除节所指的旧表述:无文档/账本改动。

Refs #3195

…T_NOFILE soft limit (Refs #3195)

## Summary

`ulimit -n 16` 下,heredoc / herestring 的显式重定向符 ≥ 软限时,GNU 在绑定位置报 `16: Bad file descriptor` 且不绑定该 fd;rubash 接受并正常绑定,命令照常读到 heredoc 内容(#2635 同族残余:限额门落在五条既有走线,heredoc/herestring 条目不经其中任何一条)。

本 PR 按 #2635 同口径在四处落门(+83/−2,4 文件 + 19 测回归钉):

- `src/executor/builtin_redirects.rs`(no-output 内建 setup 走线):HereDoc/HereString 条目在自家 list 位置过门,过限返回 `{fd}: Bad file descriptor`。
- `src/executor/command_input_scope.rs`(有序 walk):同上口径,过限 `Err(ExecuteError::IoError(...))`。
- `src/executor/redirection.rs`(`list_binds` 有序 walk):过限走本 walk 的失败协议(`limit_gate_fail`),命名 redirector;`failing_open_redirect_index` 并入 HereDoc/HereString 的 file-arm 分支,使限额失败诊断可路由定位。
- `src/executor/trap_exec.rs`(#2635 门的 gate 探针):HereDoc/HereString 并入 file-arm,`redirect_fd_over_limit(gate_fd).then_some(gate_fd)`,无文件预开(body 物化即 open)。

限下路径逐点核对与旧代码等价(`builtin_redirects` 旧 fall-through 对该 kind 同样 `continue`;其余三门只在过限时触发)。

## GNU semantics

`redir.c`:heredoc body 先物化(`here_document_to_fd`,`redir.c:1072`),再 `dup2` 到 redirector(`redir.c:1120`,≥ 软限时 EBADF);`redirection_error`(`redir.c:135`,EBADF 命名在 `redir.c:166-175`)默认命名 redirector。失败落在条目自己的 list 位置,此前副作用保留、此后条目不执行;`{var}` 形除外(`fcntl F_DUPFD` 分配,恒在限下)。

## Verification (Linux, bin-first, -j 1; base = master `8b48c164`, head = this branch)

- Pin `tests/issue3195_heredoc_fd_limit.rs`(19 测):头 **19/19**;基底 fail-first **2/19**(仅两对照过:fd 15 绑定、`{var}` 限下分配)。
- 相邻父面钉 `issue2635_redirect_fd_limit`:头 **12/12**。
- 三向探针(`probes/{probe1,cases1-4}.sh`,GNU 5.3.20 vs 基底 vs 头,归一化后):GNU vs 头全 MATCH,仅 `hd-multi-below`(`exec 14<<A 15<<B` 限下双 heredoc,第一条绑定丢失)一处差——基底同症既有缺陷,与限额门无关,合入后另立跟进单(钉未覆盖该形)。
- Lib 双边:头 1247/0/4 = 基底 1247/0/4,失败名集差 ∅。
- `RUSTFLAGS="-D warnings"`:全量腿欠(未在最终头上跑过,合入前由复核轮补跑);REPORT 所记调用数未实测,不作证据。
- 卫生:`git diff --check` 与 `rustfmt --edition 2021 --check`(5 RS 文件)干净。

## What this PR deletes

- 未删产品代码路径。本 PR 只新增限额门:替换的只是 heredoc/herestring 条目在过限时"静默绑定"的旧行为(该行为与 GNU 有差,见上);限下行为逐点核对不变。删除节所指的旧表述:无文档/账本改动。

Refs #3195
@caomengxuan666

Copy link
Copy Markdown
Member Author

队长复核:PASS

复核轮证据(卷宗 review-3576/CAPTAIN-VERIFY.md,腿全量落地、零 EDQUOT):

  • 机制:四门共用既有谓词 redirect_fd_over_limit(fd ≥ 软限才触发),限下路径逐点与旧代码等价;诊断 {fd}: Bad file descriptor 与 GNU 命名一致(redir.c:1072/:1120/:135,EBADF default 臂 :175);trap_exec 臂无文件预开。
  • 钉 issue3195_heredoc_fd_limit:头 19/19;基底 fail-first 2/19(过的恰为两对照格);相邻 issue2635 12/12。
  • Lib 双边:头 1247/0/4 = 基底 1247/0/4,失败名集差 ∅。
  • RUSTFLAGS="-D warnings":复核轮在最终头补跑(正文披露的欠腿),rc=0、零 warning。
  • 三方 oracle:GNU vs 头 9/10 MATCH;唯一差 hd-multi-below 为基底同症既有缺陷(base==head),非本 PR 面,合入后立跟进单。
  • 头 CI 三条红 job 唯一失败名均为 issue2875,与 master 基线名集一致,零新失败名。
  • 与 live tip(0079e4aa)交集程序化为 ∅,免 update-branch 合入。注:fix(executor): let a live fd-0 File endpoint outrank the FUNCTION_STDIN mirror in exec spawns (Refs #3046) #3461 同碰 trap_exec.rs(不同区域),若其后合须 update-branch + 合并形重验。

正文自报数字逐项复现属实;-D warnings 欠腿为明示披露且三次尝试均死于 EDQUOT 写、非警告,无需更正正文,合入正文由队长按复核结果校正该行。

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