Repository navigation
fix(executor): deliver stage {var} fd bindings through the shared applier space (rubash#2613) - #2628
Merged
Merged
Conversation
…nd fd space (rubash#2613)
GNU runs ONE do_redirections walk per pipeline element
(execute_cmd.c:2620 execute_pipeline -> redir.c:237
do_redirections) and the {var} entries allocate their descriptor
inside that same walk (redir.c:1470 redir_varassign), so a later
entry may reference the allocated descriptor by number
({v}>&9 1>&10).
The stage output preflight and the post-execution routing walk
replayed the list in a seeded descriptor space that never contains
the applier's allocation: the stage executors undo the dynamic-fd
applier before routing runs, and the preflight ran before it. A
numbered reference to the allocated slot resolved as a bad fd —
the preflight killed live stages and the routing walk dropped the
stage's payload and forced its status to 1.
Bracket both walks with the SAME applier the plain-command funnel
runs ahead of its own faces (apply -> judge -> undo), gated on the
list carrying a {var} entry; lists without one take the exact
previous path. The plain faces need no bracket: their walks run
while the funnel's applier bindings still stand.
…ier (rubash#2613)
reject_invalid_redirects validates a stage list's dup sources
against the shell's fd table plus its own overlay of the list's
numbered entries. A {var} entry's allocated descriptor is in
neither space, so a stage list referencing an earlier {var}
allocation by number ({v}>&9 9>o1.txt 1>&10, fd-mechanism audit
shape S02) was rejected with '10: Bad file descriptor' and the
command never ran — while the identical plain command passed,
because the plain funnel runs apply_dynamic_fd_var_redirects
ahead of the same gate (redir.c:237 do_redirections binds the
redir.c:1470 redir_varassign allocation in the element's one
walk; there is no stage dialect).
Apply the applier around the stage gate and undo it on every
exit; an applier failure verdict kills the stage with the
captured pipe bytes final, mirroring both the preflight arms
below and the plain funnel's return on the same verdict. Only
the gate sits inside the bracket — the word-expansion faces
below still expand $v against the outer binding, as GNU
expands a command's words before its do_redirections run.
…2613)
A function stage executes on a command-substitution clone of the
parent executor. The plain invocation reaches execute_function
with the funnel's applier bindings standing in the executing
executor's fd table, and the call's redirect walk resolves a
numbered reference to a {var} allocation against them; the stage
clone never ran the applier, so the allocated slot was missing
from its space and '{v}>&9 1>&10' on a function element silently
left fd 1 bound to the pipe — the payload went down the pipe
instead of to the dup target (redir.c:237 do_redirections;
execute_cmd.c:2620 execute_pipeline: the element's list is
applied in the element's own fork).
Run the same applier on the clone for the duration of the
execute_function call and undo it afterwards, gated on the call
carrying a {var} entry.
…sh#2613)
Nine pins in a new target,
tests/issue2613_stage_varfd_delivery_regressions.rs:
- S02 x {pipe-left, pipe-right}: {v}>&9 9>o1.txt 1>&10 — var dup,
numbered rebind of the source, reference by number.
- S04 x {pipe-left, pipe-right}: {v}>&9 9>&- 1>&10 — plus the
parent shell's fd 9 must survive (the close is the element's).
- S12 x {pipe-left, pipe-right}: {v}>&9- 1>&10 move form — plus
parent fd 9 survival.
- The fd-mechanism audit's C1 reproducer verbatim (the EBADF
headline case).
- The builtin-stage and function-stage faces of the same class.
All assert GNU bash 5.3 behavior (payload in seed.txt, PIPESTATUS
0, no Bad file descriptor diagnostic). Pins are
UNVERIFIED-BY-CAPTAIN.
…fmt-clean master)
caomengxuan666
force-pushed
the
fix/2613-stage-varfd-delivery
branch
from
November 2, 2026 23:58
ce7f7fb to
5059a24
Compare
caomengxuan666
marked this pull request as ready for review
November 2, 2026 23:58
Member
Author
|
队长验收(2026-11-03):
|
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.
Refs #2613
Defect
A pipeline stage whose redirect list references, by number, the descriptor an earlier
{var}entry in the same list allocated died with10: Bad file descriptorand never ran:GNU runs ONE do_redirections walk per pipeline element (execute_cmd.c:2620
execute_pipeline-> redir.c:237do_redirections) and the{var}entries allocate their descriptor inside that walk (redir.c:1470redir_varassign) — there is no stage dialect. rubash judged the stage's list in three descriptor spaces that never contain the applier's allocation: the stage reject gate (fd table + numbered overlay only; its fd_var arm validated the source then continued without recording the allocation), the stage output preflight (seeded state, fd_var entries skipped), and the post-execution routing walk (runs after the stage executor undid the applier). The delivery path itself (apply_external_fd_delivery) was already the shared one — the stage's auxiliary walks were the dialect.Fix — one applier, one descriptor space
Every stage auxiliary walk now runs bracketed by the SAME dynamic-fd applier the plain-command funnel runs ahead of its faces (apply -> judge -> undo), gated on the list carrying a
{var}entry; lists without one take the exact previous path:src/executor/pipeline_exec.rs— the stage reject gate inexecute_pipeline_stage_innersits inside an applier bracket; an applier failure verdict kills the stage with the captured pipe bytes final, mirroring the existing preflight arms and the plain funnel's return on the same verdict. Only the gate is bracketed: the word-expansion faces below still expand$vagainst the outer binding (GNU expands words before do_redirections).src/executor/redirection.rs—pipeline_stage_output_redirect_failsself-brackets (covers both the driver gate and the builtin stage executor's own preflight), androute_pipeline_stage_streamswraps its walk the same way (body moved toroute_pipeline_stage_streams_inner). New helpercommand_has_dynamic_fd_var_redirects.src/executor/pipeline_stages.rs— the function stage clone runs the applier for the duration of theexecute_functioncall: the plain invocation reachesexecute_functionwith the funnel's bindings standing in the executing executor's table, and the stage clone must present the same space or the call's redirect walk leaves fd 1 on the pipe.Pins — UNVERIFIED-BY-CAPTAIN
New target
tests/issue2613_stage_varfd_delivery_regressions.rs, 9 pins, all asserting GNU bash 5.3 behavior:issue2613_s02_pipe_left_var_dup_then_numbered_rebind_and_referenceissue2613_s02_pipe_right_var_dup_then_numbered_rebind_and_referenceissue2613_s04_pipe_left_var_dup_then_close_source_and_referenceissue2613_s04_pipe_right_var_dup_then_close_source_and_referenceissue2613_s12_pipe_left_move_form_reference_parent_keeps_sourceissue2613_s12_pipe_right_move_form_reference_parent_keeps_sourceissue2613_headline_c1_ebadf_stage_varfd_deliveryissue2613_builtin_stage_var_dup_referenceissue2613_function_stage_var_dup_referenceGuard stems that must stay green (captain's central verification):
issue2255_pipeline_stage_redirects,issue2272_fdvar_spawn_delivery_regressions,issue2281_pending_close_positions,issue2322_close_position_regressions,issue2483_stream_drain,issue2612_varfd_applier_walk_regressions.Cluster-local evidence (not a substitute for central verification): the audit shape battery (C1 both pipe positions, S02/S04/S12, builtin/function/compound/subshell stage faces, plus five failing-list controls incl.
2>err.txtdiagnostic routing) matches GNU bash 5.3.20 byte-for-byte after the fix, and the 9 pins pass locally.