From c57b37d29f9d04780c7f7917789cf8b424710d23 Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Tue, 31 Jan 2023 17:52:17 -0800 Subject: Handle invalid input in clear* timer --- src/bun.js/api/bun.zig | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/bun.js') diff --git a/src/bun.js/api/bun.zig b/src/bun.js/api/bun.zig index d70de3aa9..0b47bea27 100644 --- a/src/bun.js/api/bun.zig +++ b/src/bun.js/api/bun.zig @@ -3139,12 +3139,16 @@ pub const Timer = struct { return JSValue.jsNumberWithType(i32, id); } - pub fn clearTimer(timer_id: JSValue, _: *JSGlobalObject, repeats: bool) void { + pub fn clearTimer(timer_id: JSValue, globalThis: *JSGlobalObject, repeats: bool) void { JSC.markBinding(@src()); var map = if (repeats) &VirtualMachine.get().timer.interval_map else &VirtualMachine.get().timer.timeout_map; + if (!timer_id.isAnyInt()) { + return; + } + const id: Timeout.ID = .{ - .id = timer_id.toInt32(), + .id = timer_id.coerce(i32, globalThis), .repeat = @as(u32, @boolToInt(repeats)), }; var timer = map.fetchSwapRemove(id.id) orelse return; -- cgit v1.2.3