summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-03-27 21:23:30 +0100
committerBram Moolenaar <Bram@vim.org>2021-03-27 21:23:30 +0100
commitc580943965fc9b006ec233bdee4ea5380f5594ea (patch)
treef17d1e9bbebd06aac239d16dd6d16fc1ecfc88e1 /src
parent7b45d46cf7db0d2d7a4defc2d81b233a2c672b74 (diff)
patch 8.2.2666: Vim9: not enough function arguments checked for stringv8.2.2666
Problem: Vim9: not enough function arguments checked for string. Solution: Check in ch_logfile(), char2nr() and others.
Diffstat (limited to 'src')
-rw-r--r--src/channel.c5
-rw-r--r--src/eval.c3
-rw-r--r--src/evalfunc.c9
-rw-r--r--src/filepath.c4
-rw-r--r--src/testdir/test_vim9_builtin.vim31
-rw-r--r--src/version.c2
6 files changed, 54 insertions, 0 deletions
diff --git a/src/channel.c b/src/channel.c
index bdb59f0d39..fa329bdba3 100644
--- a/src/channel.c
+++ b/src/channel.c
@@ -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);
diff --git a/src/eval.c b/src/eval.c
index 6522f0f24e..f5fd3e0184 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -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;
diff --git a/src/evalfunc.c b/src/evalfunc.c
index 6d845c1663..f83559dbbe 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -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;
@@ -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;
@@ -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;
diff --git a/src/filepath.c b/src/filepath.c
index 75662b485c..e81eeb1200 100644
--- a/src/filepath.c
+++ b/src/filepath.c
@@ -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);
diff --git a/src/testdir/test_vim9_builtin.vim b/src/testdir/test_vim9_builtin.vim
index 7897db0e55..eba5ff6a41 100644
--- a/src/testdir/test_vim9_builtin.vim
+++ b/src/testdir/test_vim9_builtin.vim
@@ -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()
@@ -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]
diff --git a/src/version.c b/src/version.c
index 8e04e9a38c..da9073c357 100644
--- 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 */
/**/
+ 2666,
+/**/
2665,
/**/
2664,