Skip to content

fix(executor): expand heredoc bodies on raw-empty null commands - #3362

Closed
Uarz wants to merge 1 commit into
unixwin:masterfrom
Uarz:fix/issue-2761
Closed

Uarz wants to merge 1 commit into
unixwin:masterfrom
Uarz:fix/issue-2761

Conversation

@Uarz

@Uarz Uarz commented Nov 11, 2026

Copy link
Copy Markdown
Member

Fixes #2761

What was fixed

Heredoc bodies on raw-empty null commands were never expanded: the empty-words dispatch went through execute_empty_words_command, which bypassed the stdin pre-expansion funnel entirely, so no stdin consumer ever materialised the body.

The fix routes empty-words commands through the existing preexpand_command_stdin funnel (after the assignment loop, before the reject gate), mirroring the worded path's ordering. All three empty-words arms (raw-empty, vanished-words, post-alias) share this function, so one insertion covers them.

What was deleted

Nothing. No files, features, or tests were removed.

Verification (all run, per-item counts)

Owed

P16 divergence (pre-existing, not introduced here): $EMPTY 3<<EOF ${UNDEF:?boom} EOF — GNU exits the script (fatal in the main shell), rubash prints alive and continues. The root is the heredoc-error pre-check classifying by the original words; fixing it touches the #2681 error-adjudication layer and is left for a separate issue.

Raw-empty null commands routed through execute_empty_words_command and bypassed the stdin pre-expansion funnel, so heredoc and here-string bodies were never expanded. Route them through the existing preexpand_command_stdin funnel before the reject gate, mirroring the worded path ordering.

Refs unixwin#2761

Regression pin: tests/issue2761_heredoc_null_command_expansion.rs (18 tests; fail-first 10 failed on the unpatched tree, 18/18 pass after). Adjacent families green. GNU 5.3.20 oracle probes P1-P15, P17, P18 byte-identical.

Owed: P16 divergence ($EMPTY 3<<EOF fatal body error not fatal in the main shell) is pre-existing and left for a separate issue.
@caomengxuan666

Copy link
Copy Markdown
Member

[WIN-AGENT-AUDIT] PR #3362 第1轮 — 建议:PENDING(缺腿/队长裁定)
head: 8970551(draft)文件: src/executor/command_execute.rs + command_prepare.rs + tests/issue2761_heredoc_null_command_expansion.rs
关联 issue: #2761(open)

机制核查:本 lane 未重审 diff——issue #2761 最后一条评论(2026-11-14)明示「队长车道临时接手(Uarz 休息期间),已开工修法」,且 #3362 与 #3715 为同一 issue 的竞争实现。按既定裁定,本 issue 不并行推进,本 PR 维持 hold。

腿:未跑(hold 期间不消耗验证资源)。

F 点:无(非 FAIL 判定)。

未跑/VOID 的腿:全部——原因:队长已接管 issue #2761,本 lane 按 hold 处理;若队长裁定 #3362 胜出或需对比,再补全腿。

@caomengxuan666

Copy link
Copy Markdown
Member

【WIN-AGENT-AUDIT】
PR #3362 第2轮 — 建议:PENDING(只读评估;机制已被 master + #3842 完全吸收,是否关闭由队长裁定)
head: 8970551(draft,未变)文件: src/executor/command_execute.rs + src/executor/command_prepare.rs + tests/issue2761_heredoc_null_command_expansion.rs
关联 issue: #2761(队长已接管;本 lane 只读,不动分支)

只读机制对比(对 master ccb8614 逐 hunk 核):

GNU 依据(复核):execute_cmd.c:4626-4640 expanded-words==0 → execute_null_command;execute_cmd.c:4203-4278 force-fork 规则(fd-0/REDIR_VARASSIGN → fork);redir.c:423-434 heredoc_expand;与 #3842 审计同源。

F 点:无(非缺陷判定;系被取代判定)。

未跑/VOID 的腿:全腿未跑——只读评估 + head 未变 + 队长已接管 issue,按规程不并行续作;机制吸收结论以 master 源码逐 hunk 比对为准,未在 #3362 head 上重跑钉(其钉与 #3842 钉同族,#3842 侧已核 9/9)。

caomengxuan666 added a commit that referenced this pull request Nov 17, 2026
…c bodies in the shell (Refs #2761) (#3842)

The vanished-words arm of the empty-words dispatch passed `cmd` with
its raw words (`["$EMPTY"]`) to `execute_empty_words_command`, so the
heredoc fork classifier saw an effective word and expanded a
numbered-fd body in a fork, discarding `:=`. GNU's words==0 check
runs on the EXPANDED word list, which is empty here — the node is a
null command, and the force-fork rule (fd-0 / REDIR_VARASSIGN only)
leaves a numbered-fd body expanding in the shell, so `:=` persists.
Hand the node to the null-command path wordless, as GNU sees it.

GNU anchors (audit tree bash-5.3, verified):
- execute_cmd.c:4626-4640 — `words == 0` dispatches to
  execute_null_command.
- execute_cmd.c:4210-4216 — force-fork only for REDIR_VARASSIGN or
  a redirect targeting fd 0 / bash input; fd-3 does not force it.

Absorb note: this is the surviving remainder of Uarz #3362 after
#3715 merged (487c745). Dropped as already-in-master: both
visibility changes (`abort_on_expansion_errors`,
`preexpand_command_stdin`) and the `command_prepare.rs` insertion
block (superseded by #3715's 61-line version with the funsub-exit
latches). `preexpand_command_stdin` keeps master's `Option<i32>`
return (the #2763 latch); #3362's `()` signature was NOT taken.
Pins trimmed from 17 to the 9 shapes #3715 lacks: the
discriminating `vanished_words_numbered_heredoc_assign_persists`
(red on master by code trace, green after this hunk) plus eight
coverage pins (arithmetic x2, two-heredoc order x2, arith-error x2,
fd0-fatal x1, post-alias x1).

Verification: no cargo/rustc on this VM and the X299/server routes
are down, so no local leg ran. Pin red/green is established by code
trace (see REPORT.md); CI census (which runs all stems) adjudicates
on the PR.

Co-authored-by: Uarz <[email protected]>
@caomengxuan666

Copy link
Copy Markdown
Member

Superseded: the surviving vanished-words hunk landed in master via #3842 (cherry-picked from this PR, Uarz's authorship preserved); the two visibility changes were already in master; the command_prepare.rs block was superseded by #3715's version. Thank you — no work lost, closing as superseded.

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.

heredoc: bodies on raw-empty null commands are never expanded (empty-words dispatch bypass)

2 participants