diff options
author | Bram Moolenaar <Bram@vim.org> | 2021-01-04 16:15:58 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-01-04 16:15:58 +0100 |
commit | d1510ee9469f623c872a18b6e3c3666c0fb23c58 (patch) | |
tree | 0467d12c3f6ecf15f7402fa3e2d43298fa597c5c /src | |
parent | cef1270dec61efb3544f26ceea0f6a4f57e0198a (diff) |
patch 8.2.2299: Vim9: invalid memory access making error message flakyv8.2.2299
Problem: Vim9: invalid memory access making error message flaky.
Solution: Do not check cmd_argt for CMD_USER. (issue #7467)
Diffstat (limited to 'src')
-rw-r--r-- | src/errors.h | 2 | ||||
-rw-r--r-- | src/ex_docmd.c | 8 | ||||
-rw-r--r-- | src/testdir/test_vim9_cmd.vim | 26 | ||||
-rw-r--r-- | src/version.c | 2 | ||||
-rw-r--r-- | src/vim9compile.c | 7 | ||||
-rw-r--r-- | src/vim9execute.c | 1 |
6 files changed, 40 insertions, 6 deletions
diff --git a/src/errors.h b/src/errors.h index eb7239bd94..e71b706004 100644 --- a/src/errors.h +++ b/src/errors.h @@ -16,6 +16,8 @@ EXTERN char e_undefined_variable_str[] EXTERN char e_undefined_variable_char_str[] INIT(= N_("E121: Undefined variable: %c:%s")); #endif +EXTERN char e_ambiguous_use_of_user_defined_command[] + INIT(= N_("E464: Ambiguous use of user-defined command")); EXTERN char e_invalid_command[] INIT(= N_("E476: Invalid command")); #ifdef FEAT_EVAL diff --git a/src/ex_docmd.c b/src/ex_docmd.c index 044c18a85b..5a3a37abcb 100644 --- a/src/ex_docmd.c +++ b/src/ex_docmd.c @@ -2025,7 +2025,7 @@ do_one_cmd( if (p == NULL) { if (!ea.skip) - errormsg = _("E464: Ambiguous use of user-defined command"); + errormsg = _(e_ambiguous_use_of_user_defined_command); goto doend; } // Check for wrong commands. @@ -3531,9 +3531,11 @@ find_ex_command( eap->cmdidx = CMD_finally; #ifdef FEAT_EVAL - if (eap->cmdidx != CMD_SIZE && in_vim9script() + if (eap->cmdidx < CMD_SIZE + && in_vim9script() && !IS_WHITE_OR_NUL(*p) && *p != '\n' && *p != '!' - && (cmdnames[eap->cmdidx].cmd_argt & EX_NONWHITE_OK) == 0) + && (eap->cmdidx < 0 || + (cmdnames[eap->cmdidx].cmd_argt & EX_NONWHITE_OK) == 0)) { semsg(_(e_command_not_followed_by_white_space_str), eap->cmd); eap->cmdidx = CMD_SIZE; diff --git a/src/testdir/test_vim9_cmd.vim b/src/testdir/test_vim9_cmd.vim index ab31100682..c9e83d9bca 100644 --- a/src/testdir/test_vim9_cmd.vim +++ b/src/testdir/test_vim9_cmd.vim @@ -771,6 +771,24 @@ def Test_f_args() CheckScriptSuccess(lines) enddef +def Test_user_command_comment() + command -nargs=1 Comd echom <q-args> + + var lines =<< trim END + vim9script + Comd # comment + END + CheckScriptSuccess(lines) + + lines =<< trim END + vim9script + Comd# comment + END + CheckScriptFailure(lines, 'E1144:') + + delcommand Comd +enddef + def Test_star_command() var lines =<< trim END vim9script @@ -798,12 +816,14 @@ def Test_cmd_argument_without_colon() enddef def Test_ambiguous_user_cmd() + command Cmd1 eval 0 + command Cmd2 eval 0 var lines =<< trim END - com Cmd1 eval 0 - com Cmd2 eval 0 Cmd END - CheckScriptFailure(lines, 'E464:') + CheckDefAndScriptFailure(lines, 'E464:', 1) + delcommand Cmd1 + delcommand Cmd2 enddef def Test_command_not_recognized() diff --git a/src/version.c b/src/version.c index a905760928..07113c4b3c 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 */ /**/ + 2299, +/**/ 2298, /**/ 2297, diff --git a/src/vim9compile.c b/src/vim9compile.c index 80f918d9e0..4007641bb0 100644 --- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -7797,6 +7797,13 @@ compile_def_function(ufunc_T *ufunc, int check_return_type, cctx_T *outer_cctx) : (int (*)(char_u *, size_t, void *, cctx_T *))lookup_local, &cctx); + if (p == NULL) + { + if (cctx.ctx_skip != SKIP_YES) + emsg(_(e_ambiguous_use_of_user_defined_command)); + goto erret; + } + if (p == ea.cmd && ea.cmdidx != CMD_SIZE) { if (cctx.ctx_skip == SKIP_YES) diff --git a/src/vim9execute.c b/src/vim9execute.c index d0c2ebc706..32ed04aeef 100644 --- a/src/vim9execute.c +++ b/src/vim9execute.c @@ -3054,6 +3054,7 @@ call_def_function( goto failed; ++ectx.ec_stack.ga_len; tv = STACK_TV_BOT(-1); + ea.addr_count = 0; ea.addr_type = ADDR_LINES; ea.cmd = iptr->isn_arg.string; if (parse_cmd_address(&ea, &errormsg, FALSE) == FAIL) |