0
0
mirror of https://github.com/vim/vim.git synced 2025-09-23 03:43:49 -04:00

patch 8.2.2172: Vim9: number of arguments is not always checked

Problem:    Vim9: number of arguments is not always checked. (Yegappan
            Lakshmanan)
Solution:   Check number of arguments when calling function by name.
This commit is contained in:
Bram Moolenaar
2020-12-20 21:10:17 +01:00
parent 61e07b2394
commit 5082471f91
6 changed files with 55 additions and 8 deletions

View File

@@ -1833,6 +1833,22 @@ call_user_func(
cleanup_function_call(fc);
}
/*
* Check the argument count for user function "fp".
* Return FCERR_UNKNOWN if OK, FCERR_TOOFEW or FCERR_TOOMANY otherwise.
*/
int
check_user_func_argcount(ufunc_T *fp, int argcount)
{
int regular_args = fp->uf_args.ga_len;
if (argcount < regular_args - fp->uf_def_args.ga_len)
return FCERR_TOOFEW;
else if (!has_varargs(fp) && argcount > regular_args)
return FCERR_TOOMANY;
return FCERR_UNKNOWN;
}
/*
* Call a user function after checking the arguments.
*/
@@ -1846,15 +1862,13 @@ call_user_func_check(
dict_T *selfdict)
{
int error;
int regular_args = fp->uf_args.ga_len;
if (fp->uf_flags & FC_RANGE && funcexe->doesrange != NULL)
*funcexe->doesrange = TRUE;
if (argcount < regular_args - fp->uf_def_args.ga_len)
error = FCERR_TOOFEW;
else if (!has_varargs(fp) && argcount > regular_args)
error = FCERR_TOOMANY;
else if ((fp->uf_flags & FC_DICT) && selfdict == NULL)
error = check_user_func_argcount(fp, argcount);
if (error != FCERR_UNKNOWN)
return error;
if ((fp->uf_flags & FC_DICT) && selfdict == NULL)
error = FCERR_DICT;
else
{