mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 07:07:39 +00:00
fix: reject launchd pid sentinel values
Landed from contributor PR #39281 by @mvanhorn. Co-authored-by: Matt Van Horn <mvanhorn@gmail.com>
This commit is contained in:
@@ -102,6 +102,26 @@ describe("launchd runtime parsing", () => {
|
||||
lastExitReason: "exited",
|
||||
});
|
||||
});
|
||||
|
||||
it("does not set pid when pid = 0", () => {
|
||||
const output = ["state = running", "pid = 0"].join("\n");
|
||||
const info = parseLaunchctlPrint(output);
|
||||
expect(info.pid).toBeUndefined();
|
||||
expect(info.state).toBe("running");
|
||||
});
|
||||
|
||||
it("sets pid for positive values", () => {
|
||||
const output = ["state = running", "pid = 1234"].join("\n");
|
||||
const info = parseLaunchctlPrint(output);
|
||||
expect(info.pid).toBe(1234);
|
||||
});
|
||||
|
||||
it("does not set pid for negative values", () => {
|
||||
const output = ["state = waiting", "pid = -1"].join("\n");
|
||||
const info = parseLaunchctlPrint(output);
|
||||
expect(info.pid).toBeUndefined();
|
||||
expect(info.state).toBe("waiting");
|
||||
});
|
||||
});
|
||||
|
||||
describe("launchctl list detection", () => {
|
||||
|
||||
@@ -128,7 +128,7 @@ export function parseLaunchctlPrint(output: string): LaunchctlPrintInfo {
|
||||
const pidValue = entries.pid;
|
||||
if (pidValue) {
|
||||
const pid = Number.parseInt(pidValue, 10);
|
||||
if (Number.isFinite(pid)) {
|
||||
if (Number.isFinite(pid) && pid > 0) {
|
||||
info.pid = pid;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user