Skip to content

WIP: fix ENOEXEC script-child fd scoping (Refs #2279) - #2291

Merged
caomengxuan666 merged 4 commits into
masterfrom
fix/2279-enoexec-fd-scoping
Oct 30, 2026
Merged

caomengxuan666 merged 4 commits into
masterfrom
fix/2279-enoexec-fd-scoping

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #2279 — re-verification + fix for the ENOEXEC script-child face's fd scoping.

Re-verification on master 01ecad1 (GNU bash 5.3.20 oracle, probe files in the cluster workdir)

  • Claim (i) {v} leak: still broken for every non-empty script (empty script did not leak — the child's first inner command is what clears the funnel's single-slot undo records). Parent variable, parent fd slot, and preset values all leaked/clobbered.
  • Claim (ii) dup-input child "hangs": not reproduced on current master — the face now fails fast with EBADF; the literal hang belongs to the superseded {fd} 变量形重定向在 spawn 投递面全 kind 缺失(外部子进程拿不到 fd_var 绑定) #2272-era diagnostic binary. The underlying defect (dup binding missing) was still real and is fixed with (iii).
  • Claim (iii) command-scoped bindings invisible inside the script: still broken — the face bound only numbered outputs and fd 0. Numbered file/heredoc/dup inputs were absent (EBADF), and a parent fd at the same number stayed unshadowed: the script read and consumed the parent's binding.

Fixes (mechanism-level, GNU-cited in commit messages)

  1. execute_direct_shell_script now binds the command's numbered heredocs and inputs for the run through the compound binders (bind_numbered_heredoc_redirects — with_loop_fd_heredocs split into bind/restore halves — and open_compound_numbered_input_redirects), ahead of the fd-0 install so 3<&0 resolves against the pre-command stdin, and restores them at the boundary. It also parks the caller's fd_var delivery records (fd_var_external_undo / fd_var_pending_closes / fd_var_close_restore) across the run so execute_external's paired undo lands on the pre-command state.
  2. execute_materialized_command's redirect-rejection path now undoes the funnel's speculative {var} apply for the disk class only (a rejected disk command never reaches execute_external, the undo's owner: /bin/true {v}<seed < /missing leaked v). Builtins/functions keep the binding, byte-verified against GNU (: {v}<seed < /missing leaves v set in 5.3.20).

Pins

tests/issue2279_enoexec_fd_scoping_regressions.rs — 13 pins (numbered heredoc/file/dup visibility, shared ambient offset, {v} leak/preset/shadow cells, rejected-disk undo, builtin/spawn/stdin/ambient-File controls), all expectations byte-verified against GNU 5.3.20; observers are the script's own builtin reads or the nested rubash binary, never an ENOEXEC script child observing a spawn delivery.

Local verification (debug build of this branch): probe matrix p1–p9 + e1 + rejection shapes all byte-match GNU; pin target 13/13. CI + main-session batch adjudication still to run — this PR is Refs-only and does not close #2279.

Discovery held for the parent session (in the cluster REPORT): an ambient heredoc Text endpoint bound by ANY in-process face (group/function/script) is not materialized for spawned grandchildren — cross-face, spawn-delivery layer, not this face.

caomengxuan666 and others added 4 commits October 30, 2026 23:14
Refs #2279

GNU runs a shebangless text file in a forked child whose
do_redirections (execute_cmd.c:5884, redir.c:767-955) applies the
command's full redirect list, and whose redir_varassign
(redir.c:1133-1166) dies with the child. The in-process emulation
(execute_direct_shell_script) bound only numbered outputs and fd 0:
numbered inputs/heredocs never bound (./reader.sh 3<seed read EBADF,
and a parent fd 3 stayed unshadowed so the child read and consumed
the parent's own binding), and a {var} binding leaked into the
parent because the child's first inner command re-entered the
applier and cleared the funnel's single-slot undo records before
execute_external could replay them (an empty script leaked nothing).

- bind the numbered heredocs and inputs through the compound
  binders (bind_numbered_heredoc_redirects — with_loop_fd_heredocs
  split into bind/restore halves — and
  open_compound_numbered_input_redirects) ahead of the fd-0 install,
  so a 3<&0 dup still resolves against the pre-command stdin;
  restore them at the boundary;
- park fd_var_external_undo / fd_var_pending_closes /
  fd_var_close_restore across the run and hand them back at the
  restore block, so the caller's paired undo lands on the
  pre-command state.
… are rejected

Refs #2279

execute_materialized_command's redirect rejection skips dispatch
entirely, so a disk command never reaches execute_external — the
owner of the fd_var undo for its class — and the funnel's
apply_dynamic_fd_var_redirects leaked the variable and the
descriptor (/bin/true {v}<seed < /missing left v set; GNU: unset,
the varassign exists only in the forked child). Undo on the
rejection path for the disk class only; builtins/functions keep
the binding, matching GNU (verified against 5.3.20:
`: {v}<seed < /missing` leaves v set, success or failure).
Refs #2279

tests/issue2279_enoexec_fd_scoping_regressions.rs: 13 pins —
numbered heredoc/file/dup visibility inside the script, shared
offset for ambient dups, {var} leak/preset/shadow cells, the
rejected-disk-command undo, and controls for the builtin, spawn,
stdin and ambient-File faces. Every expectation byte-verified
against GNU bash 5.3.20 via the cluster probe files; observers are
the script's own builtin reads or the nested rubash binary, never
an ENOEXEC script child observing a spawn delivery.
@caomengxuan666
caomengxuan666 marked this pull request as ready for review October 30, 2026 23:33
@caomengxuan666
caomengxuan666 merged commit a629be4 into master Oct 30, 2026
11 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/2279-enoexec-fd-scoping branch November 2, 2026 01:09
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.

ENOEXEC 脚本子进程面 fd 作用域缺失:{fd} 变量泄漏回父壳、dup 输入挂死、命令作用域绑定不可见

1 participant