Skip to content

Commit aad5f9d

Browse files
committed
patch 8.2.2472: crash when using command line window in an autocommand
Problem: Crash when using command line window in an autocommand. (houyunsong) Solution: Save and restore au_new_curbuf.
1 parent efa1923 commit aad5f9d

3 files changed

Lines changed: 27 additions & 5 deletions

File tree

src/ex_cmds.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2710,8 +2710,9 @@ do_ecmd(
27102710
*/
27112711
if (buf != curbuf)
27122712
{
2713+
bufref_T save_au_new_curbuf;
27132714
#ifdef FEAT_CMDWIN
2714-
int save_cmdwin_type = cmdwin_type;
2715+
int save_cmdwin_type = cmdwin_type;
27152716

27162717
// BufLeave applies to the old buffer.
27172718
cmdwin_type = 0;
@@ -2728,6 +2729,7 @@ do_ecmd(
27282729
*/
27292730
if (buf->b_fname != NULL)
27302731
new_name = vim_strsave(buf->b_fname);
2732+
save_au_new_curbuf = au_new_curbuf;
27312733
set_bufref(&au_new_curbuf, buf);
27322734
apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, FALSE, curbuf);
27332735
#ifdef FEAT_CMDWIN
@@ -2737,12 +2739,14 @@ do_ecmd(
27372739
{
27382740
// new buffer has been deleted
27392741
delbuf_msg(new_name); // frees new_name
2742+
au_new_curbuf = save_au_new_curbuf;
27402743
goto theend;
27412744
}
27422745
#ifdef FEAT_EVAL
27432746
if (aborting()) // autocmds may abort script processing
27442747
{
27452748
vim_free(new_name);
2749+
au_new_curbuf = save_au_new_curbuf;
27462750
goto theend;
27472751
}
27482752
#endif
@@ -2778,6 +2782,7 @@ do_ecmd(
27782782
if (aborting() && curwin->w_buffer != NULL)
27792783
{
27802784
vim_free(new_name);
2785+
au_new_curbuf = save_au_new_curbuf;
27812786
goto theend;
27822787
}
27832788
#endif
@@ -2786,6 +2791,7 @@ do_ecmd(
27862791
{
27872792
// new buffer has been deleted
27882793
delbuf_msg(new_name); // frees new_name
2794+
au_new_curbuf = save_au_new_curbuf;
27892795
goto theend;
27902796
}
27912797
if (buf == curbuf) // already in new buffer
@@ -2831,8 +2837,7 @@ do_ecmd(
28312837
#endif
28322838
}
28332839
vim_free(new_name);
2834-
au_new_curbuf.br_buf = NULL;
2835-
au_new_curbuf.br_buf_free_count = 0;
2840+
au_new_curbuf = save_au_new_curbuf;
28362841
}
28372842

28382843
curwin->w_pcmark.lnum = 1;

src/testdir/test_autocmd.vim

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2739,9 +2739,9 @@ func Test_autocmd_closes_window()
27392739
au BufNew,BufWinLeave * e %e
27402740
file yyy
27412741
au BufNew,BufWinLeave * ball
2742-
call assert_fails('n xxx', 'E143:')
2742+
n xxx
27432743

2744-
bwipe %
2744+
%bwipe
27452745
au! BufNew
27462746
au! BufWinLeave
27472747
endfunc
@@ -2759,4 +2759,19 @@ func Test_autocmd_quit_psearch()
27592759
augroup END
27602760
endfunc
27612761

2762+
" Fuzzer found some strange combination that caused a crash.
2763+
func Test_autocmd_normal_mess()
2764+
augroup aucmd_normal_test
2765+
au BufLeave,BufWinLeave,BufHidden,BufUnload,BufDelete,BufWipeout * norm 7q/qc
2766+
augroup END
2767+
o4
2768+
silent! H
2769+
e xx
2770+
normal G
2771+
2772+
augroup aucmd_normal_test
2773+
au!
2774+
augroup END
2775+
endfunc
2776+
27622777
" 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+
2472,
753755
/**/
754756
2471,
755757
/**/

0 commit comments

Comments
 (0)