Repository navigation
WIP: fix ENOEXEC script-child fd scoping (Refs #2279) - #2291
Merged
Merged
Conversation
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.
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 #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)
{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.Fixes (mechanism-level, GNU-cited in commit messages)
execute_direct_shell_scriptnow binds the command's numbered heredocs and inputs for the run through the compound binders (bind_numbered_heredoc_redirects—with_loop_fd_heredocssplit into bind/restore halves — andopen_compound_numbered_input_redirects), ahead of the fd-0 install so3<&0resolves against the pre-command stdin, and restores them at the boundary. It also parks the caller'sfd_vardelivery records (fd_var_external_undo/fd_var_pending_closes/fd_var_close_restore) across the run soexecute_external's paired undo lands on the pre-command state.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 reachesexecute_external, the undo's owner:/bin/true {v}<seed < /missingleakedv). Builtins/functions keep the binding, byte-verified against GNU (: {v}<seed < /missingleavesvset 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.