Repository navigation
fix(executor): gate heredoc/herestring redirectors at/above the RLIMIT_NOFILE soft limit (Refs #3195) - #3576
Merged
Conversation
…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
Member
Author
队长复核:PASS复核轮证据(卷宗
正文自报数字逐项复现属实; |
caomengxuan666
marked this pull request as ready for review
November 14, 2026 08:20
This was referenced Nov 14, 2026
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
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)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,第一条绑定丢失)一处差——基底同症既有缺陷,与限额门无关,合入后另立跟进单(钉未覆盖该形)。RUSTFLAGS="-D warnings":全量腿欠(未在最终头上跑过,合入前由复核轮补跑);REPORT 所记调用数未实测,不作证据。git diff --check与rustfmt --edition 2021 --check(5 RS 文件)干净。What this PR deletes
Refs #3195