Skip to content

Commit 0d90e72

Browse files
committed
patch 8.2.1945: crash when passing NULL function to reduce()
Problem: Crash when passing NULL function to reduce(). Solution: Check for NULL pointer and give an error. (Dominique Pellé, closes #7243)
1 parent 6fd3a4b commit 0d90e72

4 files changed

Lines changed: 12 additions & 2 deletions

File tree

src/errors.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,4 +286,6 @@ EXTERN char e_cannot_add_to_null_list[]
286286
INIT(= N_("E1130: Cannot add to null list"));
287287
EXTERN char e_cannot_add_to_null_blob[]
288288
INIT(= N_("E1131: Cannot add to null blob"));
289+
EXTERN char e_missing_function_argument[]
290+
INIT(= N_("E1132: Missing function argument"));
289291
#endif

src/list.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2552,8 +2552,11 @@ f_reduce(typval_T *argvars, typval_T *rettv)
25522552
}
25532553
else
25542554
func_name = tv_get_string(&argvars[1]);
2555-
if (*func_name == NUL)
2556-
return; // type error or empty name
2555+
if (func_name == NULL || *func_name == NUL)
2556+
{
2557+
emsg(_(e_missing_function_argument));
2558+
return;
2559+
}
25572560

25582561
vim_memset(&funcexe, 0, sizeof(funcexe));
25592562
funcexe.evaluate = TRUE;

src/testdir/test_listdict.vim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,9 @@ func Test_reduce()
740740

741741
call assert_equal(42, reduce(test_null_list(), function('add'), 42))
742742
call assert_equal(42, reduce(test_null_blob(), function('add'), 42))
743+
744+
" should not crash
745+
call assert_fails('echo reduce([1], test_null_function())', 'E1132:')
743746
endfunc
744747

745748
" splitting a string to a List using split()

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
1945,
753755
/**/
754756
1944,
755757
/**/

0 commit comments

Comments
 (0)