]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.4774: crash when using a number for lambda name v8.2.4774
authorBram Moolenaar <Bram@vim.org>
Sun, 17 Apr 2022 14:06:35 +0000 (15:06 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 17 Apr 2022 14:06:35 +0000 (15:06 +0100)
Problem:    Crash when using a number for lambda name.
Solution:   Check the type of the lambda reference.

src/errors.h
src/eval.c
src/testdir/test_lambda.vim
src/version.c

index b95644a1009f47eef870ea1e8d3acf46dc0ec210..0c6134034d9469c291dbbf7a04a693db20d6a433 100644 (file)
@@ -3259,3 +3259,7 @@ EXTERN char e_nfa_regexp_missing_value_in_chr[]
        INIT(= N_("E1273: (NFA regexp) missing value in '\\%%%c'"));
 EXTERN char e_no_script_file_name_to_substitute_for_script[]
        INIT(= N_("E1274: No script file name to substitute for \"<script>\""));
+#ifdef FEAT_EVAL
+EXTERN char e_string_or_function_required_for_arrow_parens_expr[]
+       INIT(= N_("E1275: String or function required for ->(expr)"));
+#endif
index cad6887751c2d7ac619b538679db252f5d6a6072..61b09fb6b0cdff50a6f492290553d77db898d073 100644 (file)
@@ -4102,19 +4102,23 @@ eval_lambda(
        ++*arg;
        ret = eval1(arg, rettv, evalarg);
        *arg = skipwhite_and_linebreak(*arg, evalarg);
-       if (**arg == ')')
+       if (**arg != ')')
        {
-           ++*arg;
+           emsg(_(e_missing_closing_paren));
+           return FAIL;
        }
-       else
+       if (rettv->v_type != VAR_STRING && rettv->v_type != VAR_FUNC
+                                              && rettv->v_type != VAR_PARTIAL)
        {
-           emsg(_(e_missing_closing_paren));
-           ret = FAIL;
+           emsg(_(e_string_or_function_required_for_arrow_parens_expr));
+           return FAIL;
        }
+       ++*arg;
     }
     if (ret != OK)
        return FAIL;
-    else if (**arg != '(')
+
+    if (**arg != '(')
     {
        if (verbose)
        {
index e6dcb6774c3793102dab5c1dba94aac31441876b..8d06e5973c182781aebb2132ab045d0d790ea52f 100644 (file)
@@ -66,6 +66,10 @@ function Test_lambda_fails()
   echo assert_fails('echo 10->{a -> a + 2}', 'E107:')
 
   call assert_fails('eval 0->(', "E110: Missing ')'")
+  call assert_fails('eval 0->(3)()', "E1275:")
+  call assert_fails('eval 0->([3])()', "E1275:")
+  call assert_fails('eval 0->({"a": 3})()', "E1275:")
+  call assert_fails('eval 0->(xxx)()', "E121:")
 endfunc
 
 func Test_not_lamda()
index bdefc25f31e64f6bfb53f78e91be8307820fd29b..43e85e7a7cd563f55e696b15a1a903c15eb9814c 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4774,
 /**/
     4773,
 /**/