changeset 29742:2da1753e6a4a v9.0.0211

patch 9.0.0211: invalid memory access when compiling :lockvar Commit: https://github.com/vim/vim/commit/d1d8f6bacb489036d0fd479c9dd3c0102c988889 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Aug 14 21:28:32 2022 +0100 patch 9.0.0211: invalid memory access when compiling :lockvar Problem: Invalid memory access when compiling :lockvar. Solution: Don't read past the end of the line.
author Bram Moolenaar <Bram@vim.org>
date Sun, 14 Aug 2022 22:30:02 +0200
parents 71f1aa981b8e
children 806c3ef643fe
files src/testdir/test_vim9_cmd.vim src/version.c src/vim9cmds.c
diffstat 3 files changed, 18 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/testdir/test_vim9_cmd.vim
+++ b/src/testdir/test_vim9_cmd.vim
@@ -1737,6 +1737,15 @@ def Test_lockvar()
       UnLockIt()
   END
   v9.CheckScriptFailure(lines, 'E46', 1)
+
+  lines =<< trim END
+      def _()
+        s:0([], s:0)
+        lockv
+      enddef
+      defcomp
+  END
+  v9.CheckScriptFailure(lines, 'E179', 2)
 enddef
 
 def Test_substitute_expr()
--- a/src/version.c
+++ b/src/version.c
@@ -736,6 +736,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    211,
+/**/
     210,
 /**/
     209,
--- a/src/vim9cmds.c
+++ b/src/vim9cmds.c
@@ -188,10 +188,17 @@ compile_lock_unlock(
     size_t	len;
     char_u	*buf;
     isntype_T	isn = ISN_EXEC;
+    char	*cmd = eap->cmdidx == CMD_lockvar ? "lockvar" : "unlockvar";
 
     if (cctx->ctx_skip == SKIP_YES)
 	return OK;
 
+    if (*p == NUL)
+    {
+	semsg(_(e_argument_required_for_str), cmd);
+	return FAIL;
+    }
+
     // Cannot use :lockvar and :unlockvar on local variables.
     if (p[1] != ':')
     {
@@ -223,8 +230,6 @@ compile_lock_unlock(
 	ret = FAIL;
     else
     {
-	char *cmd = eap->cmdidx == CMD_lockvar ? "lockvar" : "unlockvar";
-
 	if (deep < 0)
 	    vim_snprintf((char *)buf, len, "%s! %s", cmd, p);
 	else