Skip to content

Commit 376dc48

Browse files
authored
js_event_loop: reject a non-positive timer interval (#4425)
eventLoop.timer(mode, interval) passes interval straight into furi_ms_to_ticks() with no validation. For a periodic timer an interval of 0 divides by zero in furi_event_loop_process_expired_timers() (elapsed_time / timer->interval) and is counted as expired on every event-loop pass, so a one-line script - eventLoop.timer("periodic", 0) - pins the thread running the loop. Reject interval <= 0 at the binding with a normal script-level error, matching how the other js_app modules report bad arguments. The <= 0 check also covers negative values that would otherwise wrap to a huge interval when cast to uint32_t. Signed-off-by: Cole Munz <colemunz@gmail.com>
1 parent 9c173b4 commit 376dc48

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

applications/system/js_app/modules/js_event_loop/js_event_loop.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,11 @@ static void js_event_loop_timer(struct mjs* mjs) {
263263
int32_t interval;
264264
JS_VALUE_PARSE_ARGS_OR_RETURN(mjs, &js_loop_timer_args, &mode, &interval);
265265

266+
if(interval <= 0) {
267+
mjs_prepend_errorf(mjs, MJS_BAD_ARGS_ERROR, "timer interval must be a positive number");
268+
return;
269+
}
270+
266271
JsEventLoop* module = JS_GET_CONTEXT(mjs);
267272

268273
// make timer contract

0 commit comments

Comments
 (0)