fix(native): reject signal-terminated command captures (#608)

Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com>
This commit is contained in:
Rudy Mizrahi Celekli
2026-10-06 02:09:41 +08:00
committed by GitHub
parent c73742f300
commit b81d18eeee
2 changed files with 30 additions and 1 deletions
+1 -1
View File
@@ -223,7 +223,7 @@ const captureProcess = (
finish(err(new NativeCommandFailure(tool, reason, code)));
return;
}
if (code !== 0 && options.acceptNonZero !== true) {
if (signal !== null || (code !== 0 && options.acceptNonZero !== true)) {
finish(err(new NativeCommandFailure(tool, "nonzero-exit", code)));
return;
}
@@ -0,0 +1,29 @@
import { createHash } from "node:crypto";
import { readFile } from "node:fs/promises";
import { expect, it } from "vitest";
import { XcrunCommandRunner } from "../../../../src/native/CommandRunner.js";
import { ok } from "../../../../src/domain/result.js";
it.skipIf(process.platform === "win32")(
"does not accept signal termination as an allowed nonzero exit",
async () => {
const sha256 = createHash("sha256")
.update(await readFile(process.execPath))
.digest("hex");
const runner = new XcrunCommandRunner(async () =>
ok({ path: process.execPath, sha256 }),
);
const exited = await runner.run("file", ["-e", "process.exit(1)"], {
acceptNonZero: true,
});
expect(exited.ok).toBe(true);
if (exited.ok) expect(exited.value.exitCode).toBe(1);
const killed = await runner.run(
"file",
["-e", "process.kill(process.pid, 'SIGTERM')"],
{ acceptNonZero: true },
);
expect(killed.ok).toBe(false);
if (!killed.ok) expect(killed.error.reason).toBe("nonzero-exit");
},
);