Skip to content

Commit

Permalink
patch 9.0.2030: no max callback recursion limit
Browse files Browse the repository at this point in the history
Problem:  no max callback recursion limit
Solution: bail out, if max call recursion for callback functions
          has been reached.

This checks the 'maxfuncdepth' setting and throws E169 when a callback
function recursively calls itself.

closes: #13337
closes: #13339

Signed-off-by: Christian Brabandt <cb@256bit.org>
  • Loading branch information
chrisbra committed Oct 15, 2023
1 parent 1ace49f commit 47510f3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion runtime/doc/options.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*options.txt* For Vim version 9.0. Last change: 2023 Aug 15
*options.txt* For Vim version 9.0. Last change: 2023 Oct 14


VIM REFERENCE MANUAL by Bram Moolenaar
Expand Down Expand Up @@ -5485,6 +5485,7 @@ A jump table for the options with a short description can be found at |Q_op|.
Increasing this limit above 200 also changes the maximum for Ex
command recursion, see |E169|.
See also |:function|.
Also used for maximum depth of callback functions.

*'maxmapdepth'* *'mmd'* *E223*
'maxmapdepth' 'mmd' number (default 1000)
Expand Down
6 changes: 6 additions & 0 deletions src/testdir/test_popupwin.vim
Original file line number Diff line number Diff line change
Expand Up @@ -4205,5 +4205,11 @@ func Test_popupwin_with_error()
call StopVimInTerminal(buf)
endfunc

func Test_popup_close_callback_recursive()
" this invokes the callback recursively
let winid = popup_create('something', #{callback: 'popup_close'})
redraw
call assert_fails('call popup_close(winid)', 'E169')
endfunc

" vim: shiftwidth=2 sts=2
7 changes: 7 additions & 0 deletions src/userfunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3583,6 +3583,13 @@ call_callback(

if (callback->cb_name == NULL || *callback->cb_name == NUL)
return FAIL;

if (callback_depth > p_mfd)
{
emsg(_(e_command_too_recursive));
return FAIL;
}

CLEAR_FIELD(funcexe);
funcexe.fe_evaluate = TRUE;
funcexe.fe_partial = callback->cb_partial;
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,8 @@ static char *(features[]) =

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

0 comments on commit 47510f3

Please sign in to comment.