mirror of
https://github.com/neovim/neovim.git
synced 2026-04-01 13:22:08 +00:00
vim-patch:9.1.0671: Problem: crash with WinNewPre autocommand
Problem: crash with WinNewPre autocommand, because window
structures are not yet safe to use
Solution: Don't trigger WinNewPre on :tabnew
fb3f969936
Cherry-pick doc updates from latest Vim runtime.
Co-authored-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
@@ -1233,10 +1233,12 @@ WinLeave Before leaving a window. If the window to be
|
|||||||
Not used for ":qa" or ":q" when exiting Vim.
|
Not used for ":qa" or ":q" when exiting Vim.
|
||||||
Before WinClosed.
|
Before WinClosed.
|
||||||
*WinNewPre*
|
*WinNewPre*
|
||||||
WinNewPre Before creating a new window. Triggered
|
WinNewPre Before creating a new window. Triggered
|
||||||
before commands that modify window layout by
|
before commands that modify window layout by
|
||||||
creating a split or new tab page. Not done for
|
creating a split.
|
||||||
the first window, when Vim has just started.
|
Not done when creating tab pages and for the
|
||||||
|
first window, as the window structure is not
|
||||||
|
initialized yet and so is generally not safe.
|
||||||
It is not allowed to modify window layout
|
It is not allowed to modify window layout
|
||||||
while executing commands for the WinNewPre
|
while executing commands for the WinNewPre
|
||||||
event.
|
event.
|
||||||
|
|||||||
@@ -4362,6 +4362,10 @@ void free_tabpage(tabpage_T *tp)
|
|||||||
///
|
///
|
||||||
/// It will edit the current buffer, like after :split.
|
/// It will edit the current buffer, like after :split.
|
||||||
///
|
///
|
||||||
|
/// Does not trigger WinNewPre, since the window structures
|
||||||
|
/// are not completely setup yet and could cause dereferencing
|
||||||
|
/// NULL pointers
|
||||||
|
///
|
||||||
/// @param after Put new tabpage after tabpage "after", or after the current
|
/// @param after Put new tabpage after tabpage "after", or after the current
|
||||||
/// tabpage in case of 0.
|
/// tabpage in case of 0.
|
||||||
/// @param filename Will be passed to apply_autocmds().
|
/// @param filename Will be passed to apply_autocmds().
|
||||||
@@ -4391,8 +4395,6 @@ int win_new_tabpage(int after, char *filename)
|
|||||||
|
|
||||||
curtab = newtp;
|
curtab = newtp;
|
||||||
|
|
||||||
trigger_winnewpre();
|
|
||||||
|
|
||||||
// Create a new empty window.
|
// Create a new empty window.
|
||||||
if (win_alloc_firstwin(old_curtab->tp_curwin) == OK) {
|
if (win_alloc_firstwin(old_curtab->tp_curwin) == OK) {
|
||||||
// Make the new Tab page the new topframe.
|
// Make the new Tab page the new topframe.
|
||||||
|
|||||||
BIN
test/old/testdir/crash/nullpointer
Normal file
BIN
test/old/testdir/crash/nullpointer
Normal file
Binary file not shown.
@@ -276,6 +276,7 @@ endfunc
|
|||||||
func Test_win_tab_autocmd()
|
func Test_win_tab_autocmd()
|
||||||
let g:record = []
|
let g:record = []
|
||||||
|
|
||||||
|
defer CleanUpTestAuGroup()
|
||||||
augroup testing
|
augroup testing
|
||||||
au WinNewPre * call add(g:record, 'WinNewPre')
|
au WinNewPre * call add(g:record, 'WinNewPre')
|
||||||
au WinNew * call add(g:record, 'WinNew')
|
au WinNew * call add(g:record, 'WinNew')
|
||||||
@@ -295,7 +296,7 @@ func Test_win_tab_autocmd()
|
|||||||
|
|
||||||
call assert_equal([
|
call assert_equal([
|
||||||
\ 'WinNewPre', 'WinLeave', 'WinNew', 'WinEnter',
|
\ 'WinNewPre', 'WinLeave', 'WinNew', 'WinEnter',
|
||||||
\ 'WinLeave', 'TabLeave', 'WinNewPre', 'WinNew', 'WinEnter', 'TabNew', 'TabEnter',
|
\ 'WinLeave', 'TabLeave', 'WinNew', 'WinEnter', 'TabNew', 'TabEnter',
|
||||||
\ 'WinLeave', 'TabLeave', 'WinClosed', 'TabClosed', 'WinEnter', 'TabEnter',
|
\ 'WinLeave', 'TabLeave', 'WinClosed', 'TabClosed', 'WinEnter', 'TabEnter',
|
||||||
\ 'WinLeave', 'WinClosed', 'WinEnter'
|
\ 'WinLeave', 'WinClosed', 'WinEnter'
|
||||||
\ ], g:record)
|
\ ], g:record)
|
||||||
@@ -306,7 +307,7 @@ func Test_win_tab_autocmd()
|
|||||||
bwipe somefile
|
bwipe somefile
|
||||||
|
|
||||||
call assert_equal([
|
call assert_equal([
|
||||||
\ 'WinLeave', 'TabLeave', 'WinNewPre', 'WinNew', 'WinEnter', 'TabNew', 'TabEnter',
|
\ 'WinLeave', 'TabLeave', 'WinNew', 'WinEnter', 'TabNew', 'TabEnter',
|
||||||
\ 'WinLeave', 'TabLeave', 'WinEnter', 'TabEnter',
|
\ 'WinLeave', 'TabLeave', 'WinEnter', 'TabEnter',
|
||||||
\ 'WinClosed', 'TabClosed'
|
\ 'WinClosed', 'TabClosed'
|
||||||
\ ], g:record)
|
\ ], g:record)
|
||||||
@@ -323,9 +324,6 @@ func Test_win_tab_autocmd()
|
|||||||
\ 'WinNewPre', 'WinLeave', 'WinNew', 'WinEnter'
|
\ 'WinNewPre', 'WinLeave', 'WinNew', 'WinEnter'
|
||||||
\ ], g:record)
|
\ ], g:record)
|
||||||
|
|
||||||
augroup testing
|
|
||||||
au!
|
|
||||||
augroup END
|
|
||||||
unlet g:record
|
unlet g:record
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
@@ -337,17 +335,15 @@ func Test_WinNewPre()
|
|||||||
au WinNewPre * call add(g:layouts_pre, winlayout())
|
au WinNewPre * call add(g:layouts_pre, winlayout())
|
||||||
au WinNew * call add(g:layouts_post, winlayout())
|
au WinNew * call add(g:layouts_post, winlayout())
|
||||||
augroup END
|
augroup END
|
||||||
|
defer CleanUpTestAuGroup()
|
||||||
split
|
split
|
||||||
call assert_notequal(g:layouts_pre[0], g:layouts_post[0])
|
call assert_notequal(g:layouts_pre[0], g:layouts_post[0])
|
||||||
split
|
split
|
||||||
call assert_equal(g:layouts_pre[1], g:layouts_post[0])
|
call assert_equal(g:layouts_pre[1], g:layouts_post[0])
|
||||||
call assert_notequal(g:layouts_pre[1], g:layouts_post[1])
|
call assert_notequal(g:layouts_pre[1], g:layouts_post[1])
|
||||||
|
" not triggered for tabnew
|
||||||
tabnew
|
tabnew
|
||||||
call assert_notequal(g:layouts_pre[2], g:layouts_post[1])
|
call assert_equal(2, len(g:layouts_pre))
|
||||||
call assert_notequal(g:layouts_pre[2], g:layouts_post[2])
|
|
||||||
augroup testing
|
|
||||||
au!
|
|
||||||
augroup END
|
|
||||||
unlet g:layouts_pre
|
unlet g:layouts_pre
|
||||||
unlet g:layouts_post
|
unlet g:layouts_post
|
||||||
|
|
||||||
@@ -390,9 +386,6 @@ func Test_WinNewPre()
|
|||||||
let g:caught += 1
|
let g:caught += 1
|
||||||
endtry
|
endtry
|
||||||
call assert_equal(4, g:caught)
|
call assert_equal(4, g:caught)
|
||||||
augroup testing
|
|
||||||
au!
|
|
||||||
augroup END
|
|
||||||
unlet g:caught
|
unlet g:caught
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
@@ -2900,7 +2893,8 @@ endfunc
|
|||||||
|
|
||||||
func Test_autocmd_nested()
|
func Test_autocmd_nested()
|
||||||
let g:did_nested = 0
|
let g:did_nested = 0
|
||||||
augroup Testing
|
defer CleanUpTestAuGroup()
|
||||||
|
augroup testing
|
||||||
au WinNew * edit somefile
|
au WinNew * edit somefile
|
||||||
au BufNew * let g:did_nested = 1
|
au BufNew * let g:did_nested = 1
|
||||||
augroup END
|
augroup END
|
||||||
@@ -2910,7 +2904,7 @@ func Test_autocmd_nested()
|
|||||||
bwipe! somefile
|
bwipe! somefile
|
||||||
|
|
||||||
" old nested argument still works
|
" old nested argument still works
|
||||||
augroup Testing
|
augroup testing
|
||||||
au!
|
au!
|
||||||
au WinNew * nested edit somefile
|
au WinNew * nested edit somefile
|
||||||
au BufNew * let g:did_nested = 1
|
au BufNew * let g:did_nested = 1
|
||||||
@@ -4458,6 +4452,38 @@ func Test_BufEnter_botline()
|
|||||||
set hidden&vim
|
set hidden&vim
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
" those commands caused null pointer access, see #15464
|
||||||
|
func Test_WinNewPre_crash()
|
||||||
|
defer CleanUpTestAuGroup()
|
||||||
|
let _cmdheight=&cmdheight
|
||||||
|
augroup testing
|
||||||
|
au!
|
||||||
|
autocmd WinNewPre * redraw
|
||||||
|
augroup END
|
||||||
|
tabnew
|
||||||
|
tabclose
|
||||||
|
augroup testing
|
||||||
|
au!
|
||||||
|
autocmd WinNewPre * wincmd t
|
||||||
|
augroup END
|
||||||
|
tabnew
|
||||||
|
tabclose
|
||||||
|
augroup testing
|
||||||
|
au!
|
||||||
|
autocmd WinNewPre * wincmd b
|
||||||
|
augroup END
|
||||||
|
tabnew
|
||||||
|
tabclose
|
||||||
|
augroup testing
|
||||||
|
au!
|
||||||
|
autocmd WinNewPre * set cmdheight+=1
|
||||||
|
augroup END
|
||||||
|
tabnew
|
||||||
|
tabclose
|
||||||
|
let &cmdheight=_cmdheight
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
|
||||||
" This was using freed memory
|
" This was using freed memory
|
||||||
func Test_autocmd_BufWinLeave_with_vsp()
|
func Test_autocmd_BufWinLeave_with_vsp()
|
||||||
new
|
new
|
||||||
|
|||||||
@@ -220,6 +220,12 @@ func Test_crash1_3()
|
|||||||
call term_sendkeys(buf, args)
|
call term_sendkeys(buf, args)
|
||||||
call TermWait(buf, 150)
|
call TermWait(buf, 150)
|
||||||
|
|
||||||
|
let file = 'crash/nullpointer'
|
||||||
|
let cmn_args = "%s -u NONE -i NONE -n -e -s -S %s -c ':qa!'\<cr>"
|
||||||
|
let args = printf(cmn_args, vim, file)
|
||||||
|
call term_sendkeys(buf, args)
|
||||||
|
call TermWait(buf, 50)
|
||||||
|
|
||||||
let file = 'crash/heap_overflow3'
|
let file = 'crash/heap_overflow3'
|
||||||
let cmn_args = "%s -u NONE -i NONE -n -X -m -n -e -s -S %s -c ':qa!'"
|
let cmn_args = "%s -u NONE -i NONE -n -X -m -n -e -s -S %s -c ':qa!'"
|
||||||
let args = printf(cmn_args, vim, file)
|
let args = printf(cmn_args, vim, file)
|
||||||
|
|||||||
Reference in New Issue
Block a user