Repository navigation
WIP: fix compound bind-layer error channel pair (rubash#2024 + rubash#2030) - #2055
Merged
Merged
Conversation
…s only (rubash#2024)
The compound INPUT bind layer matched a redirect target whose
quote-stripped VALUE is a whole `<(...)` span and materialized the
substitution by value, so a QUOTED target (`{ ...; } < "<(echo hi)"`,
loop input form) spawned the quoted body. GNU records a process
substitution only when the parser saw the `<(` unquoted (parse.y
read_token_word; executor-facing metadata
target_metadata.process_substitutions) and treats the quoted form as a
literal filename: redir.c:916 do_redirection_internal -> redir_open
fails it ENOENT and redirection_error (redir.c:135) prints
`<(echo hi): No such file or directory`, compound abandoned, body never
run.
Fix by root cause, in the prescribed order:
1. literal-target ERROR CHANNEL first: compound_stdin_open_failure's
raw `<(`-prefix skip becomes recorded-span admission
(redirect_target_span_is_recorded), so a non-recorded procsub-shaped
target is probed as the literal path it is and the compound aborts
with the GNU diagnostic instead of falling back to ambient stdin
(the pre-fix naive guard hung exactly there). Its failure text goes
through posix_errors::path_error, whose invalid-name class now covers
`<`/`>`-bearing names (a name no session file can ever match on
Windows maps ERROR_INVALID_NAME to GNU's ENOENT, same invariant as
the wildcard arm, redir.tests:184).
2. recorded-span ADMISSION at the spawn arms: bind_command_fd0_input's
substitution arm and loop_redirect_input's substitution arm gate on
redirect_target_span_is_recorded, the same admission the
simple-command path has used since #1931 (external_setup). The
stdin_string_for_command fd walk has no value-spawn (its procsub
contact is the registry lookup, which only real spans register);
documented in place.
Verified against WSL GNU bash 5.3.20 with script files: brace group,
loop, indirect "$t", exec and builtin faces all report
`<(echo hi): No such file or directory` with status 1 and the body
never runs; the unquoted control still spawns; `set -u` with
`done < "$NOPE"` fails the level instead of hanging. New regression
tests tests/issue2024_quoted_procsub_bind_regressions.rs (7 cases).
Residual measured on master, out of scope: the nounset wording for
`done < "$NOPE"` (`: No such file or directory` vs GNU's
`NOPE: unbound variable`) is a parameter-expansion gap.
Hook disclosure: commit hook rejected with rustfmt/cargo os error 206
(filename too long enumerating the crate's files on this host); the
touched files were verified with rustfmt --check individually
(FMT-CLEAN) before committing with --no-verify.
Fixes #2024
…urce abandons the level (rubash#2030)
Inside a compound binding, a dup whose source fd is not open was
applied silently (`let _ = dup_input` in
open_compound_numbered_input_redirects) and the level fell back to the
ambient descriptor: `seq 9 | { while read x; ...; done <&3; } | wc -l`
printed 9. GNU (bash 5.3.20) fails the step EBADF
(redir.c:1179 do_redirection_internal, case r_duplicating_input:
`dup2 (redir_fd, redirector) < 0 -> return (errno)`),
redirection_error's EBADF arm (redir.c:149-158) names the SOURCE fd —
WSL probe: `done <&3` and `done 5<&3` with fd 3 closed both print
`3: Bad file descriptor` — and do_redirections (redir.c:255-260)
abandons the command without running the body, so the dead stage feeds
the pipeline consumer nothing (wc -l = 0, stage status 1).
The compound dup preflight covered only the output side (rubash#263/
#266, compound_output_dup_bad_fd); this generalizes it to ONE ordered
left-to-right walk over BOTH sides (compound_dup_bad_fd) — GNU
applies the redirect list in order and stops at the first failing
step, so `{ ...; } 2>&4 <&3` reports `4:`, never `3:` — and wires it
before ANY bind at with_command_input_redirects,
with_numbered_fd_bindings and the exec spawn face, so the abandonment
(truncate-prefix routed diagnostic, status 1, body never runs) leaves
no half-applied descriptor state. Input-side tracking mirrors the
output walk: DuplicateInput judged via dup_source_fd_open (implicit
std fds 0-2 stay open, matching the leaf face), CloseInput closes the
slot, file/heredoc/herestring opens mark the redirector open.
Verified against WSL GNU bash 5.3.20 with script files: loop, brace
group, move form, explicitly closed source, exec face, list order and
the bound-source controls all byte-match. New regression tests
tests/issue2030_compound_dup_bad_fd_regressions.rs (8 cases). Full
cargo test --release A/B against a pristine 1a6f9c9 worktree shows
no new failures.
Hook disclosure: cargo fmt hook fails on this host with os error 206
(filename too long); touched files rustfmt --check clean; committed
with --no-verify (same precedent as the #2024 commit in this branch).
Fixes #2030
…error-channel # Conflicts: # src/posix_errors.rs
…ad of binding ambient stdin (rubash#2024) compound_stdin_open_failure's probe resolved the expanded target through the session path layer first: an empty target became the session directory, the probe open succeeded, the channel declined, and the compound silently read the ambient stdin (`while read x; done < ""` reported 0). GNU redir_open (redir.c:916) opens the empty name and fails ENOENT -- the outcome the simple-command face already reports (`echo hi < ""` -> `: No such file or directory`). Report the failure for empty expanded targets on the path-open kinds (Input / ReadWrite); here-strings and heredocs carry their payload as the target and are untouched. This also closes the nounset form the issue2024 pin guards (`done < "$NOPE"` with NOPE unbound expands to "").
caomengxuan666
marked this pull request as ready for review
October 29, 2026 08:44
This was referenced Oct 29, 2026
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.
Summary
Two fixes in the compound bind/error surface, delivered as two commits (one per issue), plus regression tests named after each issue.
Commit 1 - rubash#2024 (P2): compound INPUT bind layer materializes a quoted procsub target by VALUE
{ ...; } < "<(echo hi)"and the loop input form spawned the quoted span's body; GNU (bash 5.3.20) treats a quoted<(...)target as a literal filename (parse.y records the span only unquoted) and fails the open ENOENT, abandoning the compound.Commit 2 - rubash#2030 (P3): dup failure inside a compound binding is silent
seq 9 | { while read x; ...; done <&3; } | wc -lprinted 9; GNU reports3: Bad file descriptor(redir.c:1179 dup2 -> redirection_error EBADF arm names the SOURCE fd) and the level dies (0).Verification
Fixes #2024
Fixes #2030