mirror of
https://github.com/neovim/neovim.git
synced 2025-10-26 12:27:24 +00:00
fix(api): avoid open_win UAF if target buf deleted by autocmds
Problem: WinNew and win_enter autocommands can delete the target buffer to switch to, causing a heap-use-after-free. Solution: store a bufref to the buffer, check it before attempting to switch.
This commit is contained in:
@@ -1581,6 +1581,14 @@ describe('API/win', function()
|
||||
api.nvim_open_win(api.nvim_create_buf(true, true), false, { split = 'left' })
|
||||
eq(true, eval('fired'))
|
||||
end)
|
||||
|
||||
it('no heap-use-after-free if target buffer deleted by autocommands', function()
|
||||
local cur_buf = api.nvim_get_current_buf()
|
||||
local new_buf = api.nvim_create_buf(true, true)
|
||||
command('autocmd WinNew * ++once call nvim_buf_delete(' .. new_buf .. ', #{force: 1})')
|
||||
api.nvim_open_win(new_buf, true, { split = 'left' })
|
||||
eq(cur_buf, api.nvim_get_current_buf())
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('set_config', function()
|
||||
|
||||
Reference in New Issue
Block a user