]> granicus.if.org Git - vim/commitdiff
patch 8.2.1796: Vim9: invalid memory access with weird function name v8.2.1796
authorBram Moolenaar <Bram@vim.org>
Sun, 4 Oct 2020 11:42:34 +0000 (13:42 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 4 Oct 2020 11:42:34 +0000 (13:42 +0200)
Problem:    Vim9: invalid memory access with weird function name. (Dhiraj
            Mishra)
Solution:   Check the name is valid.  Add a test.

src/testdir/test_vim9_func.vim
src/userfunc.c
src/version.c

index 509c7fa7e180de78fe645f093e6b12119448504a..4f741bb45d923d7441be7f1e5317376d3c7361e6 100644 (file)
@@ -1906,6 +1906,32 @@ def Test_closure_in_map()
   delete('XclosureDir', 'rf')
 enddef
 
+def Test_invalid_function_name()
+  var lines =<< trim END
+      vim9script
+      def s: list<string>
+  END
+  CheckScriptFailure(lines, 'E129:')
+
+  lines =<< trim END
+      vim9script
+      def g: list<string>
+  END
+  CheckScriptFailure(lines, 'E129:')
+
+  lines =<< trim END
+      vim9script
+      def <SID>: list<string>
+  END
+  CheckScriptFailure(lines, 'E884:')
+
+  lines =<< trim END
+      vim9script
+      def F list<string>
+  END
+  CheckScriptFailure(lines, 'E488:')
+enddef
+
 def Test_partial_call()
   var Xsetlist = function('setloclist', [0])
   Xsetlist([], ' ', {'title': 'test'})
index 1d96a358a8b83fc58890b1a9ce30ef0e44fc674d..39d8fb25be57d9bfccbb5804e8abd215d1de23b4 100644 (file)
@@ -2374,6 +2374,7 @@ trans_function_name(
     int                extra = 0;
     lval_T     lv;
     int                vim9script;
+    static char *e_function_name = N_("E129: Function name required");
 
     if (fdp != NULL)
        CLEAR_POINTER(fdp);
@@ -2401,7 +2402,7 @@ trans_function_name(
     if (end == start)
     {
        if (!skip)
-           emsg(_("E129: Function name required"));
+           emsg(_(e_function_name));
        goto theend;
     }
     if (end == NULL || (lv.ll_tv != NULL && (lead > 2 || lv.ll_range)))
@@ -2517,6 +2518,12 @@ trans_function_name(
        }
        len = (int)(end - lv.ll_name);
     }
+    if (len <= 0)
+    {
+       if (!skip)
+           emsg(_(e_function_name));
+       goto theend;
+    }
 
     // In Vim9 script a user function is script-local by default.
     vim9script = ASCII_ISUPPER(*start) && in_vim9script();
index 984da5f24bdb4ecf8eb4e7b0aa8b6ab62da12723..09109b045684b972466f45360fd52fe5498f1d93 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1796,
 /**/
     1795,
 /**/