mirror of
https://github.com/oven-sh/bun
synced 2026-02-16 13:51:47 +00:00
Fix shell crash when piping assignments into commands (#22336)
## Summary - Fixes crash when running shell commands with variable assignments piped to other commands - Resolves #15714 ## Problem The shell was crashing with "Invalid tag" error when running commands like: ```bash bun exec "FOO=bar BAR=baz | echo hi" ``` ## Root Cause In `Pipeline.zig`, the `cmds` array was allocated with the wrong size: - It used `node.items.len` (which includes assignments) - But only filled entries for actual commands (assignments are skipped in pipelines) - This left uninitialized memory that caused crashes when accessed ## Solution Changed the allocation to use the correct `cmd_count` instead of `node.items.len`: ```zig // Before this.cmds = if (cmd_count >= 1) bun.handleOom(this.base.allocator().alloc(CmdOrResult, this.node.items.len)) else null; // After this.cmds = if (cmd_count >= 1) bun.handleOom(this.base.allocator().alloc(CmdOrResult, cmd_count)) else null; ``` ## Test plan ✅ Added comprehensive regression test in `test/regression/issue/15714.test.ts` that: - Tests the exact case from the issue - Tests multiple assignments - Tests single assignment - Tests assignments in middle of pipeline - Verified test fails on main branch (exit code 133 = SIGTRAP) - Verified test passes with fix 🤖 Generated with [Claude Code](https://claude.ai/code) --------- Co-authored-by: Claude Bot <claude-bot@bun.sh> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Zack Radisic <56137411+zackradisic@users.noreply.github.com>
This commit is contained in:
@@ -95,7 +95,7 @@ fn setupCommands(this: *Pipeline) ?Yield {
|
||||
break :brk i;
|
||||
};
|
||||
|
||||
this.cmds = if (cmd_count >= 1) bun.handleOom(this.base.allocator().alloc(CmdOrResult, this.node.items.len)) else null;
|
||||
this.cmds = if (cmd_count >= 1) bun.handleOom(this.base.allocator().alloc(CmdOrResult, cmd_count)) else null;
|
||||
if (this.cmds == null) return null;
|
||||
var pipes = bun.handleOom(this.base.allocator().alloc(Pipe, if (cmd_count > 1) cmd_count - 1 else 1));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user