Skip to content

Commit c580943

Browse files
committed
patch 8.2.2666: Vim9: not enough function arguments checked for string
Problem: Vim9: not enough function arguments checked for string. Solution: Check in ch_logfile(), char2nr() and others.
1 parent 7b45d46 commit c580943

File tree

6 files changed

+54
-0
lines changed

6 files changed

+54
-0
lines changed

src/channel.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4883,6 +4883,11 @@ f_ch_logfile(typval_T *argvars, typval_T *rettv UNUSED)
48834883
// Don't open a file in restricted mode.
48844884
if (check_restricted() || check_secure())
48854885
return;
4886+
if (in_vim9script()
4887+
&& (check_for_string_arg(argvars, 0) == FAIL
4888+
|| check_for_string_arg(argvars, 1) == FAIL))
4889+
return;
4890+
48864891
fname = tv_get_string(&argvars[0]);
48874892
if (argvars[1].v_type == VAR_STRING)
48884893
opt = tv_get_string_buf(&argvars[1], buf);

src/eval.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5298,6 +5298,9 @@ var2fpos(
52985298
return &pos;
52995299
}
53005300

5301+
if (in_vim9script() && check_for_string_arg(varp, 0) == FAIL)
5302+
return NULL;
5303+
53015304
name = tv_get_string_chk(varp);
53025305
if (name == NULL)
53035306
return NULL;

src/evalfunc.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2521,6 +2521,8 @@ f_changenr(typval_T *argvars UNUSED, typval_T *rettv)
25212521
static void
25222522
f_char2nr(typval_T *argvars, typval_T *rettv)
25232523
{
2524+
if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL)
2525+
return;
25242526
if (has_mbyte)
25252527
{
25262528
int utf8 = 0;
@@ -2685,11 +2687,16 @@ f_confirm(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
26852687
char_u *typestr;
26862688
int error = FALSE;
26872689

2690+
if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL)
2691+
return;
2692+
26882693
message = tv_get_string_chk(&argvars[0]);
26892694
if (message == NULL)
26902695
error = TRUE;
26912696
if (argvars[1].v_type != VAR_UNKNOWN)
26922697
{
2698+
if (in_vim9script() && check_for_string_arg(argvars, 1) == FAIL)
2699+
return;
26932700
buttons = tv_get_string_buf_chk(&argvars[1], buf);
26942701
if (buttons == NULL)
26952702
error = TRUE;
@@ -2698,6 +2705,8 @@ f_confirm(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
26982705
def = (int)tv_get_number_chk(&argvars[2], &error);
26992706
if (argvars[3].v_type != VAR_UNKNOWN)
27002707
{
2708+
if (in_vim9script() && check_for_string_arg(argvars, 3) == FAIL)
2709+
return;
27012710
typestr = tv_get_string_buf_chk(&argvars[3], buf2);
27022711
if (typestr == NULL)
27032712
error = TRUE;

src/filepath.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,9 +788,13 @@ f_chdir(typval_T *argvars, typval_T *rettv)
788788
rettv->vval.v_string = NULL;
789789

790790
if (argvars[0].v_type != VAR_STRING)
791+
{
791792
// Returning an empty string means it failed.
792793
// No error message, for historic reasons.
794+
if (in_vim9script())
795+
(void) check_for_string_arg(argvars, 0);
793796
return;
797+
}
794798

795799
// Return the current directory
796800
cwd = alloc(MAXPATHL);

src/testdir/test_vim9_builtin.vim

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,14 +204,41 @@ def Test_call_call()
204204
l->assert_equal([1, 2, 3])
205205
enddef
206206

207+
def Test_ch_logfile()
208+
assert_fails('ch_logfile(true)', 'E1174')
209+
assert_fails('ch_logfile("foo", true)', 'E1174')
210+
enddef
211+
207212
def Test_char2nr()
208213
char2nr('', true)->assert_equal(12354)
214+
215+
assert_fails('char2nr(true)', 'E1174')
216+
enddef
217+
218+
def Test_charclass()
219+
assert_fails('charclass(true)', 'E1174')
220+
enddef
221+
222+
def Test_chdir()
223+
assert_fails('chdir(true)', 'E1174')
209224
enddef
210225

211226
def Test_col()
212227
new
213228
setline(1, 'asdf')
214229
col([1, '$'])->assert_equal(5)
230+
231+
assert_fails('col(true)', 'E1174')
232+
enddef
233+
234+
def Test_confirm()
235+
if !has('dialog_con') && !has('dialog_gui')
236+
CheckFeature dialog_con
237+
endif
238+
239+
assert_fails('call confirm(true)', 'E1174')
240+
assert_fails('call confirm("yes", true)', 'E1174')
241+
assert_fails('call confirm("yes", "maybe", 2, true)', 'E1174')
215242
enddef
216243

217244
def Test_copy_return_type()
@@ -675,6 +702,10 @@ def Test_keys_return_type()
675702
var->assert_equal(['a', 'b'])
676703
enddef
677704

705+
def Test_line()
706+
assert_fails('line(true)', 'E1174')
707+
enddef
708+
678709
def Test_list2str_str2list_utf8()
679710
var s = "\u3042\u3044"
680711
var l = [0x3042, 0x3044]

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2666,
753755
/**/
754756
2665,
755757
/**/

0 commit comments

Comments
 (0)