Skip to content

fix(redirect): suppress stderr from builtins with 2>/dev/null#1138

Merged
chaliy merged 1 commit intomainfrom
fix/issue-1116-stderr-redirect-suppress
Apr 7, 2026
Merged

fix(redirect): suppress stderr from builtins with 2>/dev/null#1138
chaliy merged 1 commit intomainfrom
fix/issue-1116-stderr-redirect-suppress

Conversation

@chaliy
Copy link
Copy Markdown
Contributor

@chaliy chaliy commented Apr 7, 2026

Summary

  • Fix compound commands with output redirects (e.g. { cmd; } 2>/dev/null) leaking stderr via output_callback before apply_redirections ran
  • Fix glob error sentinel path in execute_simple_command returning early without calling apply_redirections

What

Two bugs caused 2>/dev/null to not suppress stderr from builtins:

  1. Streaming callback leak: When output_callback is set (streaming mode), compound commands like { ls /nonexistent; } 2>/dev/null emitted stderr via the callback during body execution, before the outer redirect could suppress it. Fix: suspend output_callback during compound body execution when output redirects are present.

  2. Glob sentinel bypass: When shopt -s failglob is enabled and a glob has no matches, the error sentinel path returned ExecResult::err() directly without routing through apply_redirections. Fix: pass the error result through apply_redirections.

Tests

  • Unit test: test_stderr_redirect_devnull_simple_and_compound (simple, compound, &>, failglob)
  • Streaming test: test_stderr_redirect_devnull_streaming (compound + callback)
  • Spec tests: redirect_stderr_suppress_ls, redirect_stderr_suppress_compound, redirect_combined_suppress_ls

Closes #1116

Two bugs fixed:

1. Compound commands with output redirects (e.g. `{ cmd; } 2>/dev/null`)
   leaked stderr via output_callback before apply_redirections ran.
   Fix: suspend output_callback during compound body execution when
   output redirects are present.

2. Glob error sentinel path in execute_simple_command returned early
   without calling apply_redirections, so `shopt -s failglob; cmd *.x
   2>/dev/null` still showed the error.
   Fix: route the sentinel error through apply_redirections.

Closes #1116
@chaliy chaliy merged commit 7f642b0 into main Apr 7, 2026
27 checks passed
@chaliy chaliy deleted the fix/issue-1116-stderr-redirect-suppress branch April 7, 2026 03:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(redirect): 2>/dev/null does not suppress stderr from builtins

1 participant