0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

patch 8.2.1051: crash when changing a list while using reduce() on it

Problem:    Crash when changing a list while using reduce() on it.
Solution:   Lock the list. (closes #6330)
This commit is contained in:
Bram Moolenaar 2020-06-24 22:07:46 +02:00
parent 65a8ed37f7
commit ca275a05d8
3 changed files with 17 additions and 2 deletions

View File

@ -2461,6 +2461,8 @@ f_reduce(typval_T *argvars, typval_T *rettv)
list_T *l = argvars[0].vval.v_list; list_T *l = argvars[0].vval.v_list;
listitem_T *li = NULL; listitem_T *li = NULL;
int r; int r;
int prev_locked = l->lv_lock;
int called_emsg_start = called_emsg;
CHECK_LIST_MATERIALIZE(l); CHECK_LIST_MATERIALIZE(l);
if (argvars[2].v_type == VAR_UNKNOWN) if (argvars[2].v_type == VAR_UNKNOWN)
@ -2480,6 +2482,7 @@ f_reduce(typval_T *argvars, typval_T *rettv)
li = l->lv_first; li = l->lv_first;
} }
l->lv_lock = VAR_FIXED; // disallow the list changing here
copy_tv(&initial, rettv); copy_tv(&initial, rettv);
for ( ; li != NULL; li = li->li_next) for ( ; li != NULL; li = li->li_next)
{ {
@ -2488,9 +2491,10 @@ f_reduce(typval_T *argvars, typval_T *rettv)
rettv->v_type = VAR_UNKNOWN; rettv->v_type = VAR_UNKNOWN;
r = call_func(func_name, -1, rettv, 2, argv, &funcexe); r = call_func(func_name, -1, rettv, 2, argv, &funcexe);
clear_tv(&argv[0]); clear_tv(&argv[0]);
if (r == FAIL) if (r == FAIL || called_emsg != called_emsg_start)
return; break;
} }
l->lv_lock = prev_locked;
} }
else else
{ {

View File

@ -709,6 +709,15 @@ func Test_reduce()
call assert_fails("call reduce({}, { acc, val -> acc + val }, 1)", 'E897:') call assert_fails("call reduce({}, { acc, val -> acc + val }, 1)", 'E897:')
call assert_fails("call reduce(0, { acc, val -> acc + val }, 1)", 'E897:') call assert_fails("call reduce(0, { acc, val -> acc + val }, 1)", 'E897:')
call assert_fails("call reduce('', { acc, val -> acc + val }, 1)", 'E897:') call assert_fails("call reduce('', { acc, val -> acc + val }, 1)", 'E897:')
let g:lut = [1, 2, 3, 4]
func EvilRemove()
call remove(g:lut, 1)
return 1
endfunc
call assert_fails("call reduce(g:lut, { acc, val -> EvilRemove() }, 1)", 'E742:')
unlet g:lut
delfunc EvilRemove
endfunc endfunc
" splitting a string to a List using split() " splitting a string to a List using split()

View File

@ -754,6 +754,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1051,
/**/ /**/
1050, 1050,
/**/ /**/