Skip to content

[bug] 'unset readonlyvar' diagnostic bypasses fd-2 redirection (writes to original stderr; 2>&1 and 2>/dev/null both ignored) #271

Closed

Description

@caomengxuan666

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

Summary: The unset builtin's readonly-variable diagnostic is written to the shell's ORIGINAL stderr instead of the command's (possibly redirected) fd 2. unset rv 2>&1 must land on stdout and unset rv 2>/dev/null must be silenced.

GNU C source owner: third_party/bash/builtins/set.def:964 (unset is implemented in set.def in this tree):

builtin_error (_("%s: cannot unset: readonly %s"), name, ...);

builtin_error writes through the current stderr redirection.

Reproducer (tests/fixtures/audit/a6-unset-ro2.sh; raw: target/issue-suites/results/source-audit/out/a6-unset-ro2.diff):

readonly rv=x
unset rv 2>&1
echo "rc=$?"
unset rv 2>/dev/null
echo "rc2=$?"

GNU 5.3.0: first diagnostic appears ON STDOUT (via 2>&1), stderr empty; second case fully silenced. rc/rc2 both 1.
rubash: stdout has no diagnostic; the message appears on the process's real stderr in BOTH cases (it leaks past 2>/dev/null).

Rubash owner: the unset builtin's readonly-error arm — writes via eprintln!/default stderr rather than the executor's redirected stderr writer (the same class as #250, but the redirect-open path there; this is the builtin diagnostic path).

Classification: rubash-caused. Error-hygiene divergence: scripts that silence unset errors (very common around optional-variable cleanup) get stderr pollution and wrong capture in $(...) contexts.

Activity

  1. caomengxuan666 commented on Sep 27, 2026

    @caomengxuan666
    MemberAuthor

    已修复并合入 master(commit 2c78889b,lane wt6/builtin2;GNU 引用与全矩阵验证见提交——回归 24/24、set-e/set-x/errors 真基线平价)。感谢报告!

  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