Repository navigation
Conversation
CallContext.Out/Outf drop the error from the underlying write, and the dispatcher only looked at the builtin's own return code. So echo, printf, sed, sort, grep, cut, wc and the other builtins that print through Out exited 0 on ENOSPC/EIO/EFBIG and left a truncated file. Wrap the builtin's stdout in a WriteGuard that remembers the first write error and fails every later write with it, so builtins that check their writes stop early. When the builtin otherwise succeeded, the dispatcher prints one `<cmd>: write error: <reason>` line and sets the status to 1, as bash does. Builtins that already failed and said why (cat, head, uniq) are left alone, and a broken pipe stays silent. The find -exec / xargs child dispatch gets the same treatment. Found by Jacob Hayes with patina (https://github.com/JacobHayes/patina). Environment: Datadog workspace Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
CallContext.Out/Outfdrop the error from the underlying write, and the dispatcher only looked at the builtin's own return code. Soecho,printf,sed,awk,sort,grep,cut,wc,ls,find,stringsandsha256sumexited 0 on ENOSPC/EIO/EFBIG and left a truncated redirect target.The dispatcher now wraps the builtin's stdout in a
builtins.WriteGuard, which remembers the first write error and fails every later write with it:<cmd>: write error: <reason>line and sets the status to 1, as bash does (e.g.echo: write error: no space left on device; lowercase like rshell's other messages andtr's existing write error).cat,head,uniq) aren't reported twice.find -exec/xargschild dispatch gets the same treatment.Credit
Found by Jacob Hayes with his deterministic-simulation tool patina (finding #1: SILENT oracle, random EIO leg, about 25k runs; reproduces natively with RLIMIT_FSIZE). Findings thread: https://dd.slack.com/archives/D0AC8RLB21J/p1793475631273749
Tests
interp/builtin_write_error_test.gogives the runner a stdout that fails with ENOSPC:TestBuiltinWriteErrorReported: echo, printf, sed, sort, grep, wc, cut, cat, head and uniq each exit 1 with exactly one stderr line.TestBuiltinWriteErrorFormat: the exact echo message.TestBuiltinWriteErrorBrokenPipeSilent: EPIPE prints nothing.The first two fail on main for the Out-based builtins.
go test ./...passes exceptTestPSPentestLargePIDListDoesNotHanginbuiltins/ps, which fails the same way on clean main on this host (it has real processes with the PIDs the test assumes are missing).🤖 Generated with Claude Code