Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/codex/app-server-processes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,12 @@ function listDarwinSnapshots(uid: number | undefined): ProcessSnapshot[] {
// Top-level exec failure propagates: callers decide their own safe default
// (restart flow → treat as none; staleness check → unknown, never "fresh").
const output = uid !== undefined
? execFileSync("ps", ["-u", String(uid), "-o", "pid=,command="], {
? execFileSync("/bin/ps", ["-u", String(uid), "-o", "pid=,command="], {
encoding: "utf-8",
stdio: ["ignore", "pipe", "ignore"],
timeout: 5_000,
})
: execFileSync("ps", ["-axo", "pid=,uid=,command="], {
: execFileSync("/bin/ps", ["-axo", "pid=,uid=,command="], {
encoding: "utf-8",
stdio: ["ignore", "pipe", "ignore"],
timeout: 5_000,
Expand Down Expand Up @@ -444,7 +444,7 @@ function readLinuxProcStartMs(pid: number): number | null {
/** `ps` lstart → epoch ms, or null (macOS). */
function readDarwinProcStartMs(pid: number): number | null {
try {
const out = execFileSync("ps", ["-o", "lstart=", "-p", String(pid)], {
const out = execFileSync("/bin/ps", ["-o", "lstart=", "-p", String(pid)], {
encoding: "utf-8",
stdio: ["ignore", "pipe", "ignore"],
timeout: 4_000,
Expand Down Expand Up @@ -493,7 +493,7 @@ export function readProcessStartMsBatch(
if (pids.length === 0) return out;
if (platform === "darwin") {
try {
const stdout = execFileSync("ps", ["-o", "pid=,lstart=", "-p", pids.join(",")], {
const stdout = execFileSync("/bin/ps", ["-o", "pid=,lstart=", "-p", pids.join(",")], {
encoding: "utf-8",
stdio: ["ignore", "pipe", "ignore"],
timeout: 3_000,
Expand Down
12 changes: 12 additions & 0 deletions tests/codex-app-server-processes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,18 @@ describe("CLI /api sync wiring for stale app-servers (#476)", () => {
});
});

describe("process utility invocation source guards", () => {
const processSource = readFileSync(
join(import.meta.dir, "..", "src", "codex", "app-server-processes.ts"),
"utf8",
);

test("pins every Darwin ps invocation to the system binary", () => {
expect(processSource.match(/execFileSync\(\s*["']\/bin\/ps["']/g) ?? []).toHaveLength(4);
expect(processSource).not.toMatch(/execFileSync\(\s*["']ps["']/);
});
});

describe("Windows Win32_Process owner enumeration (#476)", () => {
const processSource = readFileSync(
join(import.meta.dir, "..", "src", "codex", "app-server-processes.ts"),
Expand Down
Loading