Skip to content

WIP: fix(exec,net): quoted procsub targets are literal on exec redirects; serve /dev/tcp in read + external fd-0 <> (rubash#2090, rubash#2091) - #2097

Merged
caomengxuan666 merged 4 commits into
masterfrom
fix/fd-batch-2090-2091
Oct 29, 2026
Merged

caomengxuan666 merged 4 commits into
masterfrom
fix/fd-batch-2090-2091

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

fd 批两单:#2090(exec 引号 procsub 目标被物化执行)+ #2091(#1964 残余 /dev/tcp 三格复测后两格实修、一格已覆盖记账)。

#2090 — exec 持久重定向的引号 procsub 目标是字面文件名

execute_stdio_only_exec_redirect 与 execute_dynamic_fd_var_redirect 仅凭去引号后的目标值(strip_prefix("<(") / strip_prefix(">("))准入 procsub,无 recorded-span 检查。GNU expand_word_internal(subst.c:11365-11372)在 < 被引号(Q_DOUBLE_QUOTES)时拒绝该 span,故 exec {fd}< "<(touch MARKER)" 是字面打开——ENOENT 诊断、body 永不运行。rubash 却 spawn 了 body(MARKER 被建)且物化「成功」把诊断整个吞掉;同一值准入还使 exec {fd}<> / {fd}> / {fd}>> 与普通 exec > / < 臂 spawn 引号 span、或拿 span 顶替已存在的字面文件来读。

修法:exec 持久路径的全部 procsub 准入点统一过 #1931 起其他物化臂共用的 recorded-span 检查(external_setup::redirect_target_span_is_recorded)。引号目标落回字面打开:< 报 ENOENT、>/>>/<> 建字面文件、已存在的字面按原样读。未引号 span(有记录)准入不变,流式绑定无回归。

钉:tests/issue2090_exec_quoted_procsub_regressions.rs 6 钉(修复前树恰 5 钉红、未引号对照两树皆绿)。GNU bash 5.3.20 脚本文件逐字节对照:seed + a/b/b2/c2/d 对照形 + 更宽 {fd} 类 20/22 SAME;余 2 格(u-rw、out2u)经基线 A/B 证明为修复前既存分歧(GNU 在 RDWR procsub 管道 EOF 形状上挂起、RW 伴随账本两构建都建空文件、持久输出 procsub body 时序),非本单面,记工区 REPORT。

#2091 — #1964 残余 net 格:复测后两格实修

立案三格在当前 master 复测:

  • append 面(: >>、echo hi >>、/bin/echo hi >> /dev/tcp)与 : <>:已覆盖(各恰 1 连接、投递完好,立案后已结算)——不硬修,本批钉为对照防回退。
  • read x <> /dev/tcp/...(含 plain < 孪生格)实修:read 内建的 serve 阶梯手搓文件路径翻译、从不分类 net 拼写,喂出静默 EOF(x 空、0 连接、无诊断)。现按 shell 拼写过 special-paths 注册表分类 → open_net_redirect 一次连接(拒绝连接的首行由 connect_net_stream 内发出,与其他面一致)→ socket 瞬时绑 fd 0 由 read_virtual_fd_stdin 服务(同 fifo/device 分支形态);连接错误按 read < /dev/fd/N with closed N: silent rc=1 instead of GNU error, /proc/self/fd/N same #721 先例在 serve 内报为重定向失败。GNU 依据 redir.c netopen。
  • 外部 cat <<EOF <> /dev/tcp/...(及 plain cat <>、管道形)实修:外部 fd-0 ReadWrite 臂裸开翻译后的伪路径,报不带目标名的裸 ENOENT、连接从未发生。现 net 目标先走 open_net_redirect 再入该臂;拒绝连接时双行诊断带目标名、rc=1。

两面均为:探针自身不带连接副作用、探针与 bind 共用同一次连接结算,与 #1967 已修 > 面口径一致。

钉:tests/issue2091_devtcp_residual_regressions.rs 7 钉(hermetic:进程内 TcpListener 绑 127.0.0.1:0 随机端口、问候+字节记录、#1968 式结算计数;修复前树恰 6 修复钉红、append 对照两树皆绿)。

与 #2042 的边界

#2091 立案三格中 append 已结算、: <> 已覆盖;本批实修的两面(read serve 阶梯、外部 fd-0 RW 臂)均在 #2042 所列五面之外,未触其「内建面 loopback 双开」子面——无双修。另有一相邻发现(外部命令上非胜出 fd-0 net 重定向从不执行其 open:输出正确但 0 连接 vs GNU 1),根因在 winner 探针环的纯度设计(#1950),本批未修,建议归宿 = 外部重定向探针/bind 架构批(#2042 姊妹批),详见工区 REPORT。

门

  • CI 为门(本 PR):ubuntu 全套 + Windows goldens/canaries。
  • 本地:cargo check --locked --all-targets(RUSTFLAGS="-C debuginfo=0 -D warnings")净;lib 套 961/1/3(唯一红 = 基线 ownership 钉,基线同红);相关钉批槽外直跑全绿(issue1820/1963/1964/1966/2024/2090/2091);issue1968 的 3 钉在基线与修复树同红(Linux 环境依赖、其判官为 Windows CI),非回归。fd 敏感钉按纪律在构建槽外执行(槽以 fd 9 持 flock)。

Fixes #2090
Fixes #2091

…teral filenames

The exec persistent-redirect arms (execute_stdio_only_exec_redirect
and execute_dynamic_fd_var_redirect) admitted a process substitution
from the quote-stripped target VALUE alone: strip_prefix("<(") /
strip_prefix(">(") with no recorded-span check. GNU
expand_word_internal (subst.c:11365-11372) refuses the span when the
'<' was quoted (Q_DOUBLE_QUOTES), so exec {fd}< "<(touch MARKER)"
is a literal open — ENOENT diagnostic, body never runs. rubash
spawned the body (MARKER created) and the materialized 'success'
swallowed the diagnostic whole; the same value-only admission made
exec {fd}<> / {fd}> / {fd}>> and the plain exec > / < arms spawn
quoted spans or read a span instead of an existing literal file.

Gate every procsub admission in the exec persistent path on the
recorded-span check every other materialization arm uses since
rubash#1931 (external_setup redirect_target_span_is_recorded). A
quoted target now falls through to the literal open: '<' reports
ENOENT, '>'/'>>'/'<>' create the literal file, and an existing
literal is read as-is. Unquoted spans are admitted exactly as
before (recorded), so streaming binds are unchanged.

Regression pins: tests/issue2090_exec_quoted_procsub_regressions.rs
(6 pins; 5 fail on the pre-fix tree, the unquoted control passes on
both). Verified against GNU bash 5.3.20 with script files: the seed
plus a/b/b2/c2/d controls and the wider {fd} class are byte-equal.

Fixes #2090
…0 <> arm

Two residual #1964 faces, re-measured on current master (the append
faces and the `: <>` cell from the filing were already settled — one
connection, delivery intact — and are pinned here as controls only):

1. `read x <> /dev/tcp/...` (and the plain `<` twin): the read
   builtin's serve ladder hand-rolled filesystem path translation and
   never classified the net spelling, so it served a silent EOF — x
   empty, read status 1, ZERO connections, no diagnostic. GNU
   do_redirections connects via redir.c netopen and read serves the
   greeting. The serve ladder now classifies the shell spelling
   through the special-paths registry before path translation:
   open_net_redirect performs the one connect (a refused connect's
   first line is emitted inside connect_net_stream, as on every other
   face), the socket is bound transiently as fd 0 and served by
   read_virtual_fd_stdin like the fifo/device branches; a connect
   error is reported as the redirection's failure in the serve, per
   the rubash#721 precedent.

2. External `cat <<EOF <> /dev/tcp/...` (and plain `cat <>`, piped or
   not): the external fd-0 ReadWrite arm raw-opened the translated
   pseudo-path and failed with a bare `No such file or directory`
   naming no target, before any connection. Net targets now route
   through open_net_redirect before that branch, so the socket serves
   `<>` in both directions and a refused connect names the target
   with both diagnostic lines, rc=1.

In both faces the probe performs no connection of its own and the
bind reuses the single connect — the same settlement shape as the
rubash#1967 `>` face.

Regression pins: tests/issue2091_devtcp_residual_regressions.rs
(7 pins, hermetic in-process loopback listener on 127.0.0.1:0; the 6
fix pins fail on the pre-fix tree, the append control passes on
both). Verified against GNU bash 5.3.20 with script files and -c.

Fixes #2091
@caomengxuan666
caomengxuan666 marked this pull request as ready for review October 29, 2026 10:09
@caomengxuan666
caomengxuan666 merged commit cdb734b into master Oct 29, 2026
9 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/fd-batch-2090-2091 branch October 30, 2026 01:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant