Skip to content

Commit bdb0c5a

Browse files
mogulOpenCode Agent
andcommitted
fix(paseo-kit): validate daemon lock metadata
Reject implausible lock timestamps and non-numeric PIDs before reconciliation. Co-authored-by: OpenCode Agent <[email protected]>
1 parent d31d35a commit bdb0c5a

2 files changed

Lines changed: 46 additions & 3 deletions

File tree

‎integrations/isolation/acq-kits/paseo/files/home/paseo-start.sh‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,22 @@ reconcile_preboot_lock() {
6565
fi
6666

6767
# Node parses the lock's JSON and normalizes ISO or numeric startedAt values.
68-
# It emits one tab-separated record and rejects extra/malformed fields.
68+
# It emits one tab-separated record and rejects malformed or implausible fields.
6969
_lock_record="$(node -e '
7070
const fs = require("fs");
7171
try {
7272
const value = JSON.parse(fs.readFileSync(process.argv[1], "utf8"));
73-
const pid = Number(value.pid);
73+
const pid = value.pid;
7474
const started = value.startedAt;
7575
const epoch = typeof started === "number" ? started : Date.parse(String(started)) / 1000;
76-
if (!Number.isInteger(pid) || pid <= 1 || !Number.isFinite(epoch)) process.exit(2);
76+
if (
77+
typeof pid !== "number" ||
78+
!Number.isInteger(pid) ||
79+
pid <= 1 ||
80+
!Number.isFinite(epoch) ||
81+
epoch <= 0 ||
82+
epoch > Date.now() / 1000
83+
) process.exit(2);
7784
process.stdout.write(`${pid}\t${Math.floor(epoch)}\n`);
7885
} catch { process.exit(2); }
7986
' "$_lock" 2>/dev/null || true)"

‎integrations/isolation/acq-kits/paseo/tests/paseo-start-reconcile.test.mjs‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,39 @@ test("leaves malformed and ambiguously owned locks untouched", () => {
7777
assert.match(readFileSync(join(ambiguous.home, "paseo.pid"), "utf8"), /startedAt/);
7878
assert.match(ambiguous.log, /not the Paseo supervisor/);
7979
});
80+
81+
test("leaves implausible timestamps and non-numeric PIDs untouched", () => {
82+
for (const lock of [
83+
{ pid: 1234, startedAt: -1 },
84+
{ pid: 1234, startedAt: Math.floor(Date.now() / 1_000) + 60 },
85+
{ pid: "1234", startedAt: "1970-01-01T00:00:01Z" },
86+
]) {
87+
const root = mkdtempSync(join(tmpdir(), "paseo-reconcile-invalid-lock-"));
88+
const home = join(root, "home");
89+
const state = join(root, "state");
90+
mkdirSync(home);
91+
writeFileSync(join(home, "paseo.pid"), JSON.stringify(lock));
92+
93+
let result;
94+
try {
95+
result = execFileSync("sh", [startup], {
96+
env: {
97+
...process.env,
98+
HOME: home,
99+
PASEO_HOME: home,
100+
XDG_STATE_HOME: state,
101+
PASEO_START_RECONCILE_TEST: "1",
102+
},
103+
encoding: "utf8",
104+
stdio: "pipe",
105+
});
106+
} catch (error) {
107+
result = `${error.stdout ?? ""}${error.stderr ?? ""}`;
108+
}
109+
110+
assert.deepEqual(JSON.parse(readFileSync(join(home, "paseo.pid"), "utf8")), lock);
111+
const logPath = join(state, "paseo", "paseo-start.log");
112+
const log = existsSync(logPath) ? readFileSync(logPath, "utf8") : "";
113+
assert.match(`${log}${result}`, /malformed or ambiguous/);
114+
}
115+
});

0 commit comments

Comments
 (0)