mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-10 02:42:59 +00:00
fix(cli): reject malformed timeout options
This commit is contained in:
@@ -60,10 +60,11 @@ describe("createGlobalCommandRunner", () => {
|
||||
expect(parseTimeoutMsOrExit("0")).toBeNull();
|
||||
expect(parseTimeoutMsOrExit("-1")).toBeNull();
|
||||
expect(parseTimeoutMsOrExit(" ")).toBeNull();
|
||||
expect(parseTimeoutMsOrExit(String(Number.MAX_SAFE_INTEGER))).toBeNull();
|
||||
|
||||
expect(error).toHaveBeenCalledTimes(5);
|
||||
expect(error).toHaveBeenCalledTimes(6);
|
||||
expect(error).toHaveBeenCalledWith("--timeout must be a positive integer (seconds)");
|
||||
expect(exit).toHaveBeenCalledTimes(5);
|
||||
expect(exit).toHaveBeenCalledTimes(6);
|
||||
expect(exit).toHaveBeenCalledWith(1);
|
||||
} finally {
|
||||
error.mockRestore();
|
||||
|
||||
@@ -52,6 +52,7 @@ export type UpdateWizardOptions = {
|
||||
};
|
||||
|
||||
const INVALID_TIMEOUT_ERROR = "--timeout must be a positive integer (seconds)";
|
||||
const MAX_SAFE_TIMEOUT_SECONDS = Math.floor(Number.MAX_SAFE_INTEGER / 1000);
|
||||
|
||||
export function parseTimeoutMsOrExit(timeout?: string): number | undefined | null {
|
||||
if (timeout === undefined) {
|
||||
@@ -59,7 +60,12 @@ export function parseTimeoutMsOrExit(timeout?: string): number | undefined | nul
|
||||
}
|
||||
const trimmed = timeout.trim();
|
||||
const seconds = Number(trimmed);
|
||||
if (!/^\d+$/u.test(trimmed) || !Number.isSafeInteger(seconds) || seconds <= 0) {
|
||||
if (
|
||||
!/^\d+$/u.test(trimmed) ||
|
||||
!Number.isSafeInteger(seconds) ||
|
||||
seconds <= 0 ||
|
||||
seconds > MAX_SAFE_TIMEOUT_SECONDS
|
||||
) {
|
||||
defaultRuntime.error(INVALID_TIMEOUT_ERROR);
|
||||
defaultRuntime.exit(1);
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user