Skip to content

WIP: fix compound bind-layer error channel pair (rubash#2024 + rubash#2030) - #2055

Merged
caomengxuan666 merged 4 commits into
masterfrom
fix/2024-2030-bind-error-channel
Oct 29, 2026
Merged

caomengxuan666 merged 4 commits into
masterfrom
fix/2024-2030-bind-error-channel

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

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.
  • The literal-target ERROR CHANNEL came first (compound_stdin_open_failure recorded-span admission + GNU-shaped ENOENT text), because declining the spawn without a channel makes the compound read ambient stdin and hang. Then the spawn arms (bind_command_fd0_input, loop_redirect_input) switched to the same recorded-span admission nounset gate + real expansion print the same unbound diagnostic twice for a quoted fake procsub span #1931 uses.
  • 7 regression tests: tests/issue2024_quoted_procsub_bind_regressions.rs

Commit 2 - rubash#2030 (P3): dup failure inside a compound binding is silent

Verification

  • Every expectation byte-measured against WSL GNU bash 5.3.20 (/usr/local/bin/bash) with script files.
  • true-baseline A/B (RUB_OVERRIDE fixed vs pristine 1a6f9c9): procsub 0/0, vredir 0/0, redir 10/10 (pre-existing), coproc 4/4, read 6/6 - zero regressions.
  • Full cargo test --release A/B vs a pristine 1a6f9c9 worktree: identical failure lists except the version-metadata test that depends on tree dirtiness (passes once committed).

Fixes #2024
Fixes #2030

caomengxuan666 and others added 4 commits October 29, 2026 13:08
…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
caomengxuan666 marked this pull request as ready for review October 29, 2026 08:44
@caomengxuan666
caomengxuan666 merged commit 5edad05 into master Oct 29, 2026
9 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/2024-2030-bind-error-channel branch October 30, 2026 01:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant