Skip to content

Commit 6bcb877

Browse files
committed
patch 8.2.2463: using :arglocal in an autocommand may use freed memory
Problem: Using :arglocal in an autocommand may use freed memory. (houyunsong) Solution: Check if the arglist is locked.
1 parent 2c363a2 commit 6bcb877

3 files changed

Lines changed: 15 additions & 0 deletions

File tree

src/arglist.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,8 @@ ex_args(exarg_T *eap)
557557

558558
if (eap->cmdidx != CMD_args)
559559
{
560+
if (check_arglist_locked() == FAIL)
561+
return;
560562
alist_unlink(ALIST(curwin));
561563
if (eap->cmdidx == CMD_argglobal)
562564
ALIST(curwin) = &global_alist;
@@ -566,6 +568,8 @@ ex_args(exarg_T *eap)
566568

567569
if (*eap->arg != NUL)
568570
{
571+
if (check_arglist_locked() == FAIL)
572+
return;
569573
// ":args file ..": define new argument list, handle like ":next"
570574
// Also for ":argslocal file .." and ":argsglobal file ..".
571575
ex_next(eap);

src/testdir/test_autocmd.vim

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2717,4 +2717,13 @@ func Test_close_autocmd_tab()
27172717
%bwipe!
27182718
endfunc
27192719

2720+
" This was using freed memory.
2721+
func Test_BufNew_arglocal()
2722+
arglocal
2723+
au BufNew * arglocal
2724+
call assert_fails('drop xx', 'E1156:')
2725+
2726+
au! BufNew
2727+
endfunc
2728+
27202729
" vim: shiftwidth=2 sts=2 expandtab

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+
2463,
753755
/**/
754756
2462,
755757
/**/

0 commit comments

Comments
 (0)