mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-25 20:05:46 -06:00
fix(cli): reject unsafe sessions tail counts (#99398)
* fix(cli): reject unsafe sessions tail counts * fix(cli): reuse strict tail count parser
This commit is contained in:
@@ -188,6 +188,18 @@ describe("sessionsTailCommand", () => {
|
||||
expect(output).toContain("tool.result");
|
||||
});
|
||||
|
||||
it("rejects tail counts that exceed JavaScript safe integer precision", async () => {
|
||||
const runtime = makeRuntime();
|
||||
|
||||
await sessionsTailCommand({ store: storePath, sessionKey, tail: "9007199254740992" }, runtime);
|
||||
|
||||
expect(runtime.error).toHaveBeenCalledWith(
|
||||
"--tail must be a non-negative integer, for example --tail 25.",
|
||||
);
|
||||
expect(runtime.exit).toHaveBeenCalledWith(1);
|
||||
expect(runtime.log).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("uses a session trajectory pointer for relocated runtime files", async () => {
|
||||
const runtime = makeRuntime();
|
||||
const relocatedDir = path.join(tmpDir, "relocated-trajectories");
|
||||
|
||||
@@ -14,6 +14,7 @@ import { listSessionEntries } from "../config/sessions/session-accessor.js";
|
||||
import type { SessionEntry } from "../config/sessions/types.js";
|
||||
import { resolveStoredSessionKeyForAgentStore } from "../gateway/session-store-key.js";
|
||||
import { formatErrorMessage } from "../infra/errors.js";
|
||||
import { parseStrictNonNegativeInteger } from "../infra/parse-finite-number.js";
|
||||
import { resolveAgentIdFromSessionKey } from "../routing/session-key.js";
|
||||
import type { RuntimeEnv } from "../runtime.js";
|
||||
import {
|
||||
@@ -90,14 +91,7 @@ function parseTailCount(value: string | number | undefined): number | null {
|
||||
if (value === undefined) {
|
||||
return DEFAULT_TAIL_COUNT;
|
||||
}
|
||||
if (typeof value === "number") {
|
||||
return Number.isInteger(value) && value >= 0 ? value : null;
|
||||
}
|
||||
const trimmed = value.trim();
|
||||
if (!/^\d+$/.test(trimmed)) {
|
||||
return null;
|
||||
}
|
||||
return Number.parseInt(trimmed, 10);
|
||||
return parseStrictNonNegativeInteger(value) ?? null;
|
||||
}
|
||||
|
||||
function toOptionalString(value: unknown): string | undefined {
|
||||
|
||||
Reference in New Issue
Block a user