Skip to content

[bug] Move-fd redirections >&n- / <&n- parse as literal filenames ('&5-: No such file or directory'; GNU dups then closes) #263

Closed

Description

@caomengxuan666

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

Summary: The >&n- / <&n- move-fd redirection forms (duplicate fd n onto the target, then close n) are mis-lexed in rubash: the trailing - is not recognized, so >&5- becomes an output redirect to the literal FILENAME &5-.

GNU C source owner:

  • third_party/bash/make_cmd.c:704-718 make_redirection() case r_duplicating_output_word: when the word after >& ends in -, it strips the dash and converts to r_move_output (digits) or r_move_output_word (r_move_input/r_move_input_word for <&).
  • third_party/bash/redir.c:1253 case r_move_input_word / r_move_output_word in do_redirection_internal — dup then close (addexrclose).

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

exec 5>/dev/null
echo moved >&5-; echo "rc=$?"
exec 5</dev/null
read -u 5 x <&5-; echo "rc=$?"

GNU 5.3.0: both forms work silently (>&5- writes via fd 5 then closes it; rc=0). With exec 5>&1 first, echo moved >&5- prints moved and fd 5 ends closed.
rubash: stderr line N: &5-: No such file or directory — the operand is treated as a filename; the fd is never duplicated or closed.

Rubash owner: redirect lexer/parser — src/parser/redirections.rs (operand classification) feeding src/executor/redirection.rs; no move opcode counterpart exists for the trailing-dash dup forms.

Classification: rubash-caused. Affects fd-juggling scripts (here-doc fd shuffling, process managers); adjacent to the redir.tests family in #225.

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