# HG changeset patch # User Bram Moolenaar # Date 1615055402 -3600 # Node ID a6aec9a89184496e9e95ee279c12d926d8a2373b # Parent 85e18722945c204c9ec469b11235a606dab42b61 patch 8.2.2574: Vim9: crash when calling partial with wrong function Commit: https://github.com/vim/vim/commit/04947cc6ed313b6b99889c27d008c68a373df634 Author: Bram Moolenaar Date: Sat Mar 6 19:26:46 2021 +0100 patch 8.2.2574: Vim9: crash when calling partial with wrong function Problem: Vim9: crash when calling partial with wrong function. Solution: Check argument types of called function. (closes https://github.com/vim/vim/issues/7912) diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim --- a/src/testdir/test_vim9_func.vim +++ b/src/testdir/test_vim9_func.vim @@ -2367,6 +2367,30 @@ def Test_nested_lambda_in_closure() delete('XnestedDone') enddef +def Test_check_func_arg_types() + var lines =<< trim END + vim9script + def F1(x: string): string + return x + enddef + + def F2(x: number): number + return x + 1 + enddef + + def G(g: func): dict + return {f: g} + enddef + + def H(d: dict): string + return d.f('a') + enddef + END + + CheckScriptSuccess(lines + ['echo H(G(F1))']) + CheckScriptFailure(lines + ['echo H(G(F2))'], 'E1013:') +enddef + " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -751,6 +751,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 2574, +/**/ 2573, /**/ 2572, diff --git a/src/vim9execute.c b/src/vim9execute.c --- a/src/vim9execute.c +++ b/src/vim9execute.c @@ -797,7 +797,27 @@ call_by_name(char_u *name, int argcount, } if (ufunc != NULL) + { + if (ufunc->uf_arg_types != NULL) + { + int i; + typval_T *argv = STACK_TV_BOT(0) - argcount; + + // The function can change at runtime, check that the argument + // types are correct. + for (i = 0; i < argcount; ++i) + { + type_T *type = i < ufunc->uf_args.ga_len + ? ufunc->uf_arg_types[i] : ufunc->uf_va_type; + + if (type != NULL && check_typval_arg_type(type, + &argv[i], i + 1) == FAIL) + return FAIL; + } + } + return call_ufunc(ufunc, NULL, argcount, ectx, iptr); + } return FAIL; }