Skip to content

[bug] Empty redirection target misreported as 'ambiguous redirect' (GNU: ': No such file or directory' for >, raw-word 'Bad file descriptor' for >&) #265

Closed

Description

@caomengxuan666

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

Summary: When a redirection word expands to the EMPTY STRING, GNU does not call it ambiguous — it proceeds: > "" becomes open("") failing ENOENT, and >& "" becomes a dup of an empty fd spec failing EBADF (printing the unexpanded word). rubash classifies every empty expansion as ambiguous redirect and prints the quoted literal.

GNU C source owner:

  • third_party/bash/redir.c:895-930 (do_redirection_internal file-open cases): redirectee_word = redirection_expand(...); AMBIGUOUS_REDIRECT is returned only when redirection_expand returns NULL — i.e. the word expanded to MORE THAN ONE field (redir.c:298 redirection_expand -> w_expand multi-word). An empty single-word expansion is returned as a valid empty filename.
  • redir.c:135-197 redirection_error(): for open errors prints the EXPANDED filename (: No such file or directory); for r_duplicating_output_word EBADF with redirector==1 it prints the RAW word ("$unsetv": Bad file descriptor, redir.c:172-176).

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

echo oops > "";             echo "rc=$?"
echo oops2 > "$unsetv";      echo "rc=$?"
echo oops3 >& "$unsetv";     echo "rc=$?"
v="a b"; echo multi > $v;   echo "rc=$?"   # control: multi-word stays ambiguous on both

GNU 5.3.0: rc=1 with stderr

: No such file or directory
: No such file or directory
"$unsetv": Bad file descriptor
$v: ambiguous redirect          <- only the truly-multi-word case

rubash: rc=1 with stderr

"": ambiguous redirect
"$unsetv": ambiguous redirect
"$unsetv": ambiguous redirect
$v: ambiguous redirect

Rubash owner: src/executor/redirection.rs:76 reject_ambiguous_redirects and :118-156 — the NULL/empty branch comment cites report_ambiguous_redirect but treats empty-string expansion as ambiguous, and the diagnostic prints the raw quoted operand instead of the expanded value.

Classification: rubash-caused; same diagnostic-hygiene family as #250 (diagnostics bypassing applied fd 2) but a different wrong-invariant (empty != multi-word). Scripts probing redirectability with unset variables get the wrong errno story.

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