From a66b12378b1431f886c9b4235160abb171bcb05a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 5 Oct 2022 21:33:08 +0800 Subject: [PATCH] vim-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. https://github.com/vim/vim/commit/6bcb877ec19a647443195a54eeac60cb693fd827 --- src/nvim/arglist.c | 6 ++++++ src/nvim/testdir/test_autocmd.vim | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/src/nvim/arglist.c b/src/nvim/arglist.c index 4e122f1511..7019a6f461 100644 --- a/src/nvim/arglist.c +++ b/src/nvim/arglist.c @@ -490,6 +490,9 @@ void check_arg_idx(win_T *win) void ex_args(exarg_T *eap) { if (eap->cmdidx != CMD_args) { + if (check_arglist_locked() == FAIL) { + return; + } alist_unlink(ALIST(curwin)); if (eap->cmdidx == CMD_argglobal) { ALIST(curwin) = &global_alist; @@ -499,6 +502,9 @@ void ex_args(exarg_T *eap) } if (*eap->arg != NUL) { + if (check_arglist_locked() == FAIL) { + return; + } // ":args file ..": define new argument list, handle like ":next" // Also for ":argslocal file .." and ":argsglobal file ..". ex_next(eap); diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index 07042eab32..c320d3ca78 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -3010,6 +3010,15 @@ func Test_Visual_doautoall_redraw() %bwipe! endfunc +" This was using freed memory. +func Test_BufNew_arglocal() + arglocal + au BufNew * arglocal + call assert_fails('drop xx', 'E1156:') + + au! BufNew +endfunc + func Test_autocmd_closes_window() au BufNew,BufWinLeave * e %e file yyy