Skip to content

Commit

Permalink
patch 8.2.2666: Vim9: not enough function arguments checked for string
Browse files Browse the repository at this point in the history
Problem:    Vim9: not enough function arguments checked for string.
Solution:   Check in ch_logfile(), char2nr() and others.
  • Loading branch information
brammool committed Mar 27, 2021
1 parent 7b45d46 commit c580943
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/channel.c
Expand Up @@ -4883,6 +4883,11 @@ f_ch_logfile(typval_T *argvars, typval_T *rettv UNUSED)
// Don't open a file in restricted mode.
if (check_restricted() || check_secure())
return;
if (in_vim9script()
&& (check_for_string_arg(argvars, 0) == FAIL
|| check_for_string_arg(argvars, 1) == FAIL))
return;

fname = tv_get_string(&argvars[0]);
if (argvars[1].v_type == VAR_STRING)
opt = tv_get_string_buf(&argvars[1], buf);
Expand Down
3 changes: 3 additions & 0 deletions src/eval.c
Expand Up @@ -5298,6 +5298,9 @@ var2fpos(
return &pos;
}

if (in_vim9script() && check_for_string_arg(varp, 0) == FAIL)
return NULL;

name = tv_get_string_chk(varp);
if (name == NULL)
return NULL;
Expand Down
9 changes: 9 additions & 0 deletions src/evalfunc.c
Expand Up @@ -2521,6 +2521,8 @@ f_changenr(typval_T *argvars UNUSED, typval_T *rettv)
static void
f_char2nr(typval_T *argvars, typval_T *rettv)
{
if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL)
return;
if (has_mbyte)
{
int utf8 = 0;
Expand Down Expand Up @@ -2685,11 +2687,16 @@ f_confirm(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
char_u *typestr;
int error = FALSE;

if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL)
return;

message = tv_get_string_chk(&argvars[0]);
if (message == NULL)
error = TRUE;
if (argvars[1].v_type != VAR_UNKNOWN)
{
if (in_vim9script() && check_for_string_arg(argvars, 1) == FAIL)
return;
buttons = tv_get_string_buf_chk(&argvars[1], buf);
if (buttons == NULL)
error = TRUE;
Expand All @@ -2698,6 +2705,8 @@ f_confirm(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
def = (int)tv_get_number_chk(&argvars[2], &error);
if (argvars[3].v_type != VAR_UNKNOWN)
{
if (in_vim9script() && check_for_string_arg(argvars, 3) == FAIL)
return;
typestr = tv_get_string_buf_chk(&argvars[3], buf2);
if (typestr == NULL)
error = TRUE;
Expand Down
4 changes: 4 additions & 0 deletions src/filepath.c
Expand Up @@ -788,9 +788,13 @@ f_chdir(typval_T *argvars, typval_T *rettv)
rettv->vval.v_string = NULL;

if (argvars[0].v_type != VAR_STRING)
{
// Returning an empty string means it failed.
// No error message, for historic reasons.
if (in_vim9script())
(void) check_for_string_arg(argvars, 0);
return;
}

// Return the current directory
cwd = alloc(MAXPATHL);
Expand Down
31 changes: 31 additions & 0 deletions src/testdir/test_vim9_builtin.vim
Expand Up @@ -204,14 +204,41 @@ def Test_call_call()
l->assert_equal([1, 2, 3])
enddef

def Test_ch_logfile()
assert_fails('ch_logfile(true)', 'E1174')
assert_fails('ch_logfile("foo", true)', 'E1174')
enddef

def Test_char2nr()
char2nr('', true)->assert_equal(12354)

assert_fails('char2nr(true)', 'E1174')
enddef

def Test_charclass()
assert_fails('charclass(true)', 'E1174')
enddef

def Test_chdir()
assert_fails('chdir(true)', 'E1174')
enddef

def Test_col()
new
setline(1, 'asdf')
col([1, '$'])->assert_equal(5)

assert_fails('col(true)', 'E1174')
enddef

def Test_confirm()
if !has('dialog_con') && !has('dialog_gui')
CheckFeature dialog_con
endif

assert_fails('call confirm(true)', 'E1174')
assert_fails('call confirm("yes", true)', 'E1174')
assert_fails('call confirm("yes", "maybe", 2, true)', 'E1174')
enddef

def Test_copy_return_type()
Expand Down Expand Up @@ -675,6 +702,10 @@ def Test_keys_return_type()
var->assert_equal(['a', 'b'])
enddef

def Test_line()
assert_fails('line(true)', 'E1174')
enddef

def Test_list2str_str2list_utf8()
var s = "\u3042\u3044"
var l = [0x3042, 0x3044]
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -750,6 +750,8 @@ static char *(features[]) =

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

0 comments on commit c580943

Please sign in to comment.