diff options
author | 2023-08-12 13:14:08 +0800 | |
---|---|---|
committer | 2023-08-11 22:14:08 -0700 | |
commit | b94433ce86017dccb2e13070dcba57c11421c3ce (patch) | |
tree | b6bc5bf310f4af913d30460c2201062c2117ccb0 | |
parent | ca26780b276d32f761af37f113ca24aeeb41e92f (diff) | |
download | bun-b94433ce86017dccb2e13070dcba57c11421c3ce.tar.gz bun-b94433ce86017dccb2e13070dcba57c11421c3ce.tar.zst bun-b94433ce86017dccb2e13070dcba57c11421c3ce.zip |
Fix using uninitialized variable when formatting `config_path`. (#4129)
Close: #4128
-rw-r--r-- | src/cli.zig | 2 | ||||
-rw-r--r-- | test/cli/bun.test.ts | 20 |
2 files changed, 21 insertions, 1 deletions
diff --git a/src/cli.zig b/src/cli.zig index 1f88f3f97..7627a35ed 100644 --- a/src/cli.zig +++ b/src/cli.zig @@ -313,7 +313,7 @@ pub const Arguments = struct { defer ctx.debug.loaded_bunfig = true; var config_path: [:0]u8 = undefined; if (config_path_[0] == '/') { - @memcpy(config_buf[0..config_path.len], config_path); + @memcpy(config_buf[0..config_path_.len], config_path_); config_buf[config_path_.len] = 0; config_path = config_buf[0..config_path_.len :0]; } else { diff --git a/test/cli/bun.test.ts b/test/cli/bun.test.ts index f84f10aab..b8dd258b8 100644 --- a/test/cli/bun.test.ts +++ b/test/cli/bun.test.ts @@ -1,6 +1,8 @@ import { describe, test, expect } from "bun:test"; import { spawnSync } from "bun"; import { bunExe } from "harness"; +import { tmpdir } from "node:os"; +import fs from "node:fs"; describe("bun", () => { describe("NO_COLOR", () => { @@ -59,4 +61,22 @@ describe("bun", () => { ); }); }); + + describe("test command line arguments", () => { + test("test --config, issue #4128", () => { + const path = `${tmpdir()}/bunfig-${Date.now()}.toml`; + fs.writeFileSync(path, "[debug]"); + + const p = Bun.spawnSync({ + cmd: [bunExe(), "--config", path], + env: {}, + stderr: "inherit", + }); + try { + expect(p.exitCode).toBe(0); + } finally { + fs.unlinkSync(path); + } + }); + }); }); |