Repository navigation
fix(read): resolve /dev/stdin + EOF-without-delimiter in the read builtin (#700, #701) - #715
Merged
Merged
Conversation
The read builtin resolved a `/dev/stdin` input redirect through shell_path_to_windows, which maps the name to the CONIN$ console device on Windows. The builtin then blocked forever on the console instead of reading the piped fd 0, and the same path made `/dev/fd/N` open a nonexistent filesystem path and read empty (niubash#701 R3.1). GNU redir.c opens the `/dev/stdin` `/dev/fd/N` and `/proc/self/fd/N` alias device files, which the kernel resolves to a dup of fd N (redir.c:1153), so the builtin reads that descriptor (read.def:294). Resolve the redirect operand to its descriptor with the existing redirect_target_fd_and_move helper and serve it through the same fd-table/dup machinery as `<&N`. `<&N` itself is unchanged: the manual `&` parse is replaced by the same helper. Reference: WSL GNU bash 5.3.0. Regression cover in tests/issue700_read_dev_stdin.rs (piped stdin, file stdin, `/dev/fd/N` and `/proc/self/fd/N` for an `exec 6< f` descriptor), with a wall-clock guard so the historical hang fails the test instead of blocking CI.
…701) GNU read.def sets eof and returns EXECUTION_FAILURE when the input is exhausted before the delimiter (read.def:762-768, :949). The seekable-file fast path in FdTable::read_file_bytes_buffered (read.def:737 zreadc + :940 zsyncfd) served the trailing partial record but never set the fd-table eof flag, so a file bound to fd 0 by a compound command (`{ read l; } < f`) or an inherited descriptor (`read l <&9`) reported rc=0 at EOF-without-newline. The simple-command `< f` form is served on the read_shell_input_file path, which already set the flag; that is why only the compound/fd shapes diverged. The classic `while read` loop therefore ran one extra iteration. Record delimiter_found / limit_reached in the buffered reader and set read_eof_no_delimiter with the same rule the byte-wise (:553) and in-memory (:454) paths use. The `-n`/`-N` limit break is not EOF, and a served record is still required before the flag is set. Reference: WSL GNU bash 5.3.0. Regression cover in tests/issue701_read_eof_no_delimiter.rs (compound and inherited-fd shapes, the while-loop count for terminated and unterminated trailing records, plus newline-terminated and simple-command guards).
caomengxuan666
added a commit
that referenced
this pull request
Oct 18, 2026
…flat-region fire, return attribution (rubash#720) Three facets of the set -E ERR adjudication at subshell boundaries, all byte-pinned against WSL GNU bash 5.3.0(1) (stdin oracle): - Form 1, nested subshell fire count: GNU marks a user subshell's WHOLE body CMD_NO_FORK when it is a single subshell command (execute_cmd.c:1799-1806) and dispatches it in place — no make_child/wait_for — so the middle frame of ( (false) ) never adjudicates and GNU fires twice, not three times. Rubash now scopes a subshell_fork_collapse flag around exactly that body shape (node form in execute_subshell_command_with_redirects, flat form at the ast_exec region open) and skips the aggregate ERR adjudication under it, including the set -e early conversion (command_execute.rs). - Form 2, f() ( ) flat region: the completion ERR fire belongs to the frame that waited (execute_cmd.c:756-778, no &&/|| exemption, LINENO = the subshell's close-paren line per execute_cmd.c:696, BASH_COMMAND = the region's print_cmd text per the :703-710 fork preamble). The forkless region had no boundary fire — f() ( false ); f fired twice where GNU fires three. The parser now stamps the opener's end_line with the ) line, and every region close path runs close_flat_region_err_adjudication after the parent-state restore. - Form 4, return-in-until attribution: a return N unwinding through dispatch is the builtin's own completion (return.def:112-115); the dispatcher gate fired with the loop condition's stale status and lost the N. The gate now passes Err(Return) through to the function/source boundary, which stamps exit_code = N before the call's own gate adjudicates — ERR:7 / exit 7, matching GNU. Form 3 (cat <(false), the procsub copy path) stays tracked in #720 — it is the PR #715 read/procsub reaping area, not a trap-context fix. Companion #713 second pass: docs/audit/context-inheritance.md (the context x property inheritance/isolation table), nested-context-probes extended 24 -> 45 cases, and two new defect tickets found by the audit (#825 -T DEBUG not inherited into $( ), #826 compound redirection-failure diagnostic bypassing the ordered fd table). Tests: tests/issue720_err_trap_nested_context_regressions.rs (12 cases, one per form/edge, GNU transcripts pinned). Goldens 70/70, issue797 8/8, full-suite bidirectional comparison against origin/master shows no new failures.
caomengxuan666
added a commit
that referenced
this pull request
Oct 18, 2026
…flat-region fire, return attribution (rubash#720) Three facets of the set -E ERR adjudication at subshell boundaries, all byte-pinned against WSL GNU bash 5.3.0(1) (stdin oracle): - Form 1, nested subshell fire count: GNU marks a user subshell's WHOLE body CMD_NO_FORK when it is a single subshell command (execute_cmd.c:1799-1806) and dispatches it in place — no make_child/wait_for — so the middle frame of ( (false) ) never adjudicates and GNU fires twice, not three times. Rubash now scopes a subshell_fork_collapse flag around exactly that body shape (node form in execute_subshell_command_with_redirects, flat form at the ast_exec region open) and skips the aggregate ERR adjudication under it, including the set -e early conversion (command_execute.rs). - Form 2, f() ( ) flat region: the completion ERR fire belongs to the frame that waited (execute_cmd.c:756-778, no &&/|| exemption, LINENO = the subshell's close-paren line per execute_cmd.c:696, BASH_COMMAND = the region's print_cmd text per the :703-710 fork preamble). The forkless region had no boundary fire — f() ( false ); f fired twice where GNU fires three. The parser now stamps the opener's end_line with the ) line, and every region close path runs close_flat_region_err_adjudication after the parent-state restore. - Form 4, return-in-until attribution: a return N unwinding through dispatch is the builtin's own completion (return.def:112-115); the dispatcher gate fired with the loop condition's stale status and lost the N. The gate now passes Err(Return) through to the function/source boundary, which stamps exit_code = N before the call's own gate adjudicates — ERR:7 / exit 7, matching GNU. Form 3 (cat <(false), the procsub copy path) stays tracked in #720 — it is the PR #715 read/procsub reaping area, not a trap-context fix. Companion #713 second pass: docs/audit/context-inheritance.md (the context x property inheritance/isolation table), nested-context-probes extended 24 -> 45 cases, and two new defect tickets found by the audit (#825 -T DEBUG not inherited into $( ), #826 compound redirection-failure diagnostic bypassing the ordered fd table). Tests: tests/issue720_err_trap_nested_context_regressions.rs (12 cases, one per form/edge, GNU transcripts pinned). Goldens 70/70, issue797 8/8, full-suite bidirectional comparison against origin/master shows no new failures.
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
Fixes two
read-builtin divergences found by a differential audit against GNU bash. One PR, one commit per issue (the two are not cleanly separable: #701 R3.1 shares the #700 redirect fix).fix(read): resolve /dev/stdin instead of blocking on it (#700)fix(read): report EOF without a delimiter on the seekable read path (#701)Fixes #700
Fixes #701
Issue #700 —
read < /dev/stdinhung foreverreadresolved/dev/stdinthroughshell_path_to_windows, which maps the name to theCONIN$console device on Windows; the builtin then blocked on the console instead of the piped fd 0. GNUredir.copens the/dev/stdinalias device file, which resolves to a dup of fd N, so the builtin reads that descriptor (read.def:294). The operand is now resolved to its descriptor via the existingredirect_target_fd_and_movehelper and served through the same fd-table/dup machinery as<&N. This also fixes/dev/fd/Nand/proc/self/fd/N(issue #701 R3.1), which previously opened a nonexistent filesystem path and read empty.Issue #701 R3.2 — rc=0 at EOF without a trailing newline
FdTable::read_file_bytes_buffered(the seekable-file fast path,read.def:737zreadc +:940zsyncfd) served the trailing partial record but never set the fd-table eof flag, so a file bound to fd 0 by a compound command or an inherited descriptor reported rc=0 at EOF. The simple-command< fform is served on a different path that already set the flag, hence only the compound/fd shapes diverged andwhile readran one extra iteration. The buffered reader now tracksdelimiter_found/limit_reachedand setsread_eof_no_delimiterwith the same rule as the byte-wise (:553) and in-memory (:454) paths.Reproduction before / after
Reference: WSL GNU bash 5.3.0 (the
bashonPATHis the Niubash shim).niubaseline was 1.4.0 /e785c3c8f610; currentorigin/master(8f596779) still reproduced every case (no commit since the report touched these paths).printf 'SIN\n' | niu -c 'read -r z < /dev/stdin; echo got=[$z]'got=[SIN]got=[SIN]{ read -r z < /dev/stdin; echo got=[$z]; } < somefilegot=[SIN]got=[SIN]exec 6< f; read -r z < /dev/fd/6; echo "[$z]"[][DATA][DATA]printf 'SIN\n' | niu -c 'read -r z < /dev/fd/0; echo "[$z]"'[][SIN][SIN]printf 'abc' > f; { IFS= read -r l; echo rc=$?; } < frc=0rc=1rc=1printf 'abc' > f; exec 9< f; IFS= read -r l <&9; echo $?rc=0rc=1rc=1while IFS= read -r l; do n=$((n+1)); done < f(abc, no newline)n=1n=0n=0while IFS= read -r l; do n=$((n+1)); done < f(aaa\nbbb)n=2n=1n=1Guard: the simple-command form
IFS= read -r l < f(already correct) still reportsrc=1; a newline-terminated file still reportsrc=0.Tests
New:
tests/issue700_read_dev_stdin.rs—/dev/stdinwith piped stdin and with file stdin,/dev/fd/Nand/proc/self/fd/Nfor anexec 6< fdescriptor,/dev/fd/0from a pipe. Every case runs under a 15 s wall-clock guard, so a regression of the hang fails the test instead of blocking CI.tests/issue701_read_eof_no_delimiter.rs— both R3.2 shapes (compound and inherited fd), thewhile readcount for terminated and unterminated trailing records, plus newline-terminated and simple-command guards.Both files fail on the pre-fix tree (2 hangs + 3 wrong values for #700; 4 failures for #701) and pass after.
Ran (focused, as requested):
cargo test --test issue700_read_dev_stdin --test issue701_read_eof_no_delimiter— 11 passed.cargo testforissue275,issue276,issue277,issue279,issue280,issue324_mapfile_redirect,issue429_pipeline_stdin_redirect,issue647_function_redirect_stdin— all passed exceptissue647_function_redirect_stdin_regressions::function_call_file_redirect_survives_external_spawn, which fails identically on cleanorigin/masterin this environment (externaltrueresolved from the installed Niubash winuxcmd path is mangled toC:Userscmx...→ command not found). Pre-existing/environmental, untouched.cargo test --lib fd_table::(4) andcargo test --lib windows_impl::(8) — passed.cargo fmt --check— clean.Left alone / notes
read < /dev/fd/Nwith a closed descriptor returns rc=1 silently; GNU reportsN: No such file or directory. Pre-existing, outside the reported cases.read_input_is_regular_file/redirected_input_fdstill recognize only the&Nspelling for their checks (timeout arming, Bad-fd diagnostics); behavior for the reported cases is unaffected.src/executor/read_io.rs(redirect resolution) and the record reader insrc/executor/fd_table.rs; the general redirection engine is untouched.