To: vim_dev@googlegroups.com Subject: Patch 8.2.2666 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.2666 Problem: Vim9: not enough function arguments checked for string. Solution: Check in ch_logfile(), char2nr() and others. Files: src/channel.c, src/evalfunc.c, src/filepath.c, src/eval.c, src/testdir/test_vim9_builtin.vim *** ../vim-8.2.2665/src/channel.c 2020-09-11 19:28:16.019436292 +0200 --- src/channel.c 2021-03-27 20:21:20.906744143 +0100 *************** *** 4883,4888 **** --- 4883,4893 ---- // 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); *** ../vim-8.2.2665/src/evalfunc.c 2021-03-27 18:59:21.863043173 +0100 --- src/evalfunc.c 2021-03-27 21:15:11.089715414 +0100 *************** *** 2521,2526 **** --- 2521,2528 ---- 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,2695 **** --- 2687,2702 ---- 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,2703 **** --- 2705,2712 ---- 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; *** ../vim-8.2.2665/src/filepath.c 2021-03-27 18:59:21.863043173 +0100 --- src/filepath.c 2021-03-27 21:04:32.828187800 +0100 *************** *** 788,796 **** --- 788,800 ---- 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); *** ../vim-8.2.2665/src/eval.c 2021-03-26 22:15:22.904192129 +0100 --- src/eval.c 2021-03-27 21:08:34.659149119 +0100 *************** *** 5298,5303 **** --- 5298,5306 ---- 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; *** ../vim-8.2.2665/src/testdir/test_vim9_builtin.vim 2021-03-27 19:08:56.349496510 +0100 --- src/testdir/test_vim9_builtin.vim 2021-03-27 21:20:17.776730818 +0100 *************** *** 204,217 **** --- 204,244 ---- 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,680 **** --- 702,711 ---- 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] *** ../vim-8.2.2665/src/version.c 2021-03-27 19:08:56.353496500 +0100 --- src/version.c 2021-03-27 21:22:01.660411589 +0100 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 2666, /**/ -- Tips for aliens in New York: Land anywhere. Central Park, anywhere. No one will care or indeed even notice. -- Douglas Adams, "The Hitchhiker's Guide to the Galaxy" /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///