Skip to content

Commit

Permalink
patch 8.2.4229: possible crash when invoking timer callback fails
Browse files Browse the repository at this point in the history
Problem:    Possible crash when invoking timer callback fails.
Solution:   Initialize the typval.  Give an error for an empty callback.
            (closes #9636)
  • Loading branch information
brammool committed Jan 27, 2022
1 parent b0ad2d9 commit 745b938
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/testdir/test_vim9_builtin.vim
Original file line number Diff line number Diff line change
Expand Up @@ -4132,6 +4132,8 @@ enddef
def Test_timer_start()
CheckDefAndScriptFailure(['timer_start("a", "1")'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1'])
CheckDefAndScriptFailure(['timer_start(1, "1", [1])'], ['E1013: Argument 3: type mismatch, expected dict<any> but got list<number>', 'E1206: Dictionary required for argument 3'])
CheckDefExecAndScriptFailure(['timer_start(100, 0)'], 'E921:')
CheckDefExecAndScriptFailure(['timer_start(100, "")'], 'E921:')
enddef

def Test_timer_stop()
Expand Down
8 changes: 8 additions & 0 deletions src/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ timer_callback(timer_T *timer)
argv[0].vval.v_number = (varnumber_T)timer->tr_id;
argv[1].v_type = VAR_UNKNOWN;

rettv.v_type = VAR_UNKNOWN;
call_callback(&timer->tr_callback, -1, &rettv, 1, argv);
clear_tv(&rettv);
}
Expand Down Expand Up @@ -854,6 +855,13 @@ f_timer_start(typval_T *argvars, typval_T *rettv)
callback = get_callback(&argvars[1]);
if (callback.cb_name == NULL)
return;
if (in_vim9script() && *callback.cb_name == NUL)
{
// empty callback is not useful for a timer
emsg(_(e_invalid_callback_argument));
free_callback(&callback);
return;
}

timer = create_timer(msec, repeat);
if (timer == NULL)
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
4229,
/**/
4228,
/**/
Expand Down

0 comments on commit 745b938

Please sign in to comment.