Mercurial > vim
changeset 22794:42bb78d46354 v8.2.1945
patch 8.2.1945: crash when passing NULL function to reduce()
Commit: https://github.com/vim/vim/commit/0d90e728fe089ff1bb34d6a17f5591a96b57f734
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Nov 3 18:20:19 2020 +0100
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)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 03 Nov 2020 18:30:04 +0100 |
parents | 39efae87751b |
children | 9dbb9450336f |
files | src/errors.h src/list.c src/testdir/test_listdict.vim src/version.c |
diffstat | 4 files changed, 12 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/errors.h +++ b/src/errors.h @@ -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
--- a/src/list.c +++ b/src/list.c @@ -2552,8 +2552,11 @@ f_reduce(typval_T *argvars, typval_T *re } 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;
--- a/src/testdir/test_listdict.vim +++ b/src/testdir/test_listdict.vim @@ -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()