vim-patch:9.1.1375: [security]: possible heap UAF with quickfix dummy buffer

Problem:  heap use-after-free possible when autocommands switch away from the
          quickfix dummy buffer, but leave it open in a window.
Solution: close its windows first before attempting the wipe.
          (Sean Dewar)

related: vim/vim#17283

b4074ead5c

Co-authored-by: Sean Dewar <6256228+seandewar@users.noreply.github.com>
(cherry picked from commit 05dab80d8d)
This commit is contained in:
Sean Dewar
2025-05-10 16:24:43 +01:00
parent 034d3c8f6c
commit 3c102303f5
2 changed files with 37 additions and 10 deletions

View File

@@ -6596,4 +6596,26 @@ func Test_hardlink_fname()
call Xtest_hardlink_fname('l')
endfunc
func Test_vimgrep_dummy_buffer_crash()
augroup DummyCrash
autocmd!
" Make the dummy buffer non-current, but still open in a window.
autocmd BufReadCmd * ++once let s:dummy_buf = bufnr()
\| split | wincmd p | enew
" Autocmds from cleaning up the dummy buffer in this case should be blocked.
autocmd BufWipeout *
\ call assert_notequal(s:dummy_buf, str2nr(expand('<abuf>')))
augroup END
silent! vimgrep /./ .
redraw! " Window to freed dummy buffer used to remain; heap UAF.
call assert_equal([], win_findbuf(s:dummy_buf))
call assert_equal(0, bufexists(s:dummy_buf))
unlet! s:dummy_buf
autocmd! DummyCrash
%bw!
endfunc
" vim: shiftwidth=2 sts=2 expandtab