Skip to content

[bug] Input dup from a bad fd is silently ignored: 'cmd <&7' runs with original stdin (GNU: '7: Bad file descriptor', rc=1) #266

Closed

Description

@caomengxuan666

Found by: wt5/audit source lane (2026-09-28), script-file-verified against WSL GNU Bash 5.3.0.

Summary: command <&7 where fd 7 is not open must fail the command with 7: Bad file descriptor (rc=1). rubash silently ignores the failed dup and runs the command with the original stdin (rc=0).

GNU C source owner: third_party/bash/redir.c:1115 case r_duplicating_input in do_redirection_internal — dup2 error returns errno; reported by redir.c:135 redirection_error which for EBADF on a dup instruction prints the redirectee fd number (redir.c:149-158: filename = itos(temp->redirectee.dest)).

Reproducer (tests/fixtures/audit/a2-iso.sh case 2; raw: target/issue-suites/results/source-audit/out/a2-iso.diff):

echo badfd <&7; echo "rc=$?"

GNU 5.3.0: stderr line N: 7: Bad file descriptor, command NOT run, rc=1.
rubash: prints badfd (command ran with inherited stdin), rc=0, no diagnostic.

Control: the output direction echo badfd2 >&7 errors identically on both shells, so only the input-dup error path is missing in rubash.

Rubash owner: src/executor/redirection.rs input dup application path (error swallowed); parser side src/parser/redirections.rs.

Classification: rubash-caused. Scripts using <&$fd to probe/inherit fds silently get the wrong stream — data-corruption class, not just diagnostics.

Activity

  1. caomengxuan666 commented on Sep 27, 2026

    @caomengxuan666
    MemberAuthor

    已修复并合入 master(commit 3aec2a83,lane wt6/fdio;GNU 引用与 14 探针矩阵/真基线切片验证见提交——redir/read/heredoc/procsub 全 0 差异,regression 24/24)。感谢报告!

  2. added
    bug
    area:fd
    on Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:fdbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions