]> granicus.if.org Git - vim/commitdiff
patch 8.2.1945: crash when passing NULL function to reduce() v8.2.1945
authorBram Moolenaar <Bram@vim.org>
Tue, 3 Nov 2020 17:20:19 +0000 (18:20 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 3 Nov 2020 17:20:19 +0000 (18:20 +0100)
Problem:    Crash when passing NULL function to reduce().
Solution:   Check for NULL pointer and give an error. (Dominique PellĂ©,
            closes #7243)

src/errors.h
src/list.c
src/testdir/test_listdict.vim
src/version.c

index 1843f3d6fd903eab37c51a341882e4f886073e96..0e0377a0e75f603b4eba739168b2f7cf969debcb 100644 (file)
@@ -286,4 +286,6 @@ EXTERN char e_cannot_add_to_null_list[]
        INIT(= N_("E1130: Cannot add to null list"));
 EXTERN char e_cannot_add_to_null_blob[]
        INIT(= N_("E1131: Cannot add to null blob"));
+EXTERN char e_missing_function_argument[]
+       INIT(= N_("E1132: Missing function argument"));
 #endif
index 1da4f3d0c8b87386c658e672b29d3742c7e2b97d..beea6fae61944e21b7d97a27810793c18765e83e 100644 (file)
@@ -2552,8 +2552,11 @@ f_reduce(typval_T *argvars, typval_T *rettv)
     }
     else
        func_name = tv_get_string(&argvars[1]);
-    if (*func_name == NUL)
-       return;         // type error or empty name
+    if (func_name == NULL || *func_name == NUL)
+    {
+       emsg(_(e_missing_function_argument));
+       return;
+    }
 
     vim_memset(&funcexe, 0, sizeof(funcexe));
     funcexe.evaluate = TRUE;
index ade37f8c0c6500db6c1ec76d4a922ba94c6e9d72..6a7fc4c6820ad1d8a778e257ec8c449c1937459a 100644 (file)
@@ -740,6 +740,9 @@ func Test_reduce()
 
   call assert_equal(42, reduce(test_null_list(), function('add'), 42))
   call assert_equal(42, reduce(test_null_blob(), function('add'), 42))
+
+  " should not crash
+  call assert_fails('echo reduce([1], test_null_function())', 'E1132:')
 endfunc
 
 " splitting a string to a List using split()
index 714d038f8e7036655ba07970edbb134a7e41613a..8052de8d5ccd8c41a634919e4b9ef1bd705cec81 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1945,
 /**/
     1944,
 /**/