Skip to content

[bug] Redirection-open diagnostics bypass an already-applied stderr redirect: 'cat 2>/dev/null < /nonexistent' leaks the error (default mode, set -o posix, and comsub bodies; GNU silent) #250

Closed

Description

@caomengxuan666

Found by: wt4/regfix lane issue round (2026-09-27), script-file-verified against WSL GNU Bash 5.3.0.

Summary: A redirection-open diagnostic (< /nonexistent) is written to the shell's ORIGINAL stderr even when an earlier 2>/dev/null on the same command already redirected fd 2. GNU applies redirections left-to-right and reports the failed open through the CURRENT fd 2 (i.e. silenced). Diverges in default mode, set -o posix, and inside command-substitution bodies.

Reproducer (LF script file; target/issue-suites/results/wt4-regfix/issue-probes/p4c-diag-redirect.sh):

echo "== default mode, 2> before bad <"
cat 2>/dev/null < /nonexistent_dir_xyz/f
echo "rc=$?"
echo "== posix mode, 2> before bad <"
set -o posix
cat 2>/dev/null < /nonexistent_dir_xyz/f
echo "rc=$?"
set +o posix
echo "== comsub body, diag inside redirect scope"
v=$( cat 2>/dev/null < /nonexistent_dir_xyz/f )
echo "v=[$v] rc=$?"
echo done

GNU Bash 5.3.0: stdout only (rc=1 / rc=1 / v=[] rc=1 / done), stderr EMPTY in all three contexts.

rubash (wt4/regfix debug build): stdout identical, but stderr leaks all three diagnostics:

p4c-diag-redirect.sh: line 2: /nonexistent_dir_xyz/f: No such file or directory
p4c-diag-redirect.sh: line 6: /nonexistent_dir_xyz/f: No such file or directory
p4c-diag-redirect.sh: line 10: /nonexistent_dir_xyz/f: No such file or directory

(The reversed order < bad 2>/dev/null correctly leaks on BOTH shells — the open fails before the 2> applies; that ordering is not the bug.)

GNU C source owner: redir.c:135 redirection_error reached from redir.c:260 do_redirections — do_redirections walks the list left-to-right and each do_redirection_internal takes effect when reached, so the report for the later < open goes out through the fd 2 already pointed at /dev/null.

Rubash owner: src/executor/command_prepare.rs:515 — the input-redirect IoError arm builds the diagnostic then calls self.write_default_stderr(&stderr), which writes to the shell default stderr instead of the command's applied fd-2 target (the ordered-output machinery one file over in src/executor/redirection.rs already has the correct state.write_to_fd(self, 2, ...) pattern).

Classification: rubash-caused (WSL GNU 5.3.0 oracle). Breaks cmd 2>/dev/null < file error hygiene in configure-style scripts and pollutes captured comsub output discipline.

Artifacts: target/issue-suites/results/wt4-regfix/issue-probes/p4c-diag-redirect.sh (+ .gnu.* / .rb.* captures; p4/p4b show the control orderings).

Activity

  1. added
    bug
    on Sep 27, 2026
  2. caomengxuan666 commented on Sep 27, 2026

    @caomengxuan666
    MemberAuthor

    已修复并合入 master(commit 160d31b1,lane wt5/misc;GNU 引用与全矩阵验证见提交;相邻真 bug(v=$(f) 在 set -x 下双执行函数体)已一并修复)。感谢报告!

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions