]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.0211: invalid memory access when compiling :lockvar v9.0.0211
authorBram Moolenaar <Bram@vim.org>
Sun, 14 Aug 2022 20:28:32 +0000 (21:28 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 14 Aug 2022 20:28:32 +0000 (21:28 +0100)
Problem:    Invalid memory access when compiling :lockvar.
Solution:   Don't read past the end of the line.

src/testdir/test_vim9_cmd.vim
src/version.c
src/vim9cmds.c

index fc1354e83da3669e424b50db51d190e48db38a0b..79f19f0389a0d777019945512cb92d52ca325e1e 100644 (file)
@@ -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()
index c58386b563cee0e80d5613cda6174824f3f983a0..3f0bf5151ad21bc5344c60a0d2c7b31f84ea54b3 100644 (file)
@@ -735,6 +735,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    211,
 /**/
     210,
 /**/
index ad32c32ff7cb25d30f339ad5dac830a025161c47..35a382138bf3be8fc9e4a86fc36c6598e1d845ae 100644 (file)
@@ -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