mirror of
https://github.com/neovim/neovim
synced 2025-07-17 17:51:48 +00:00
vim-patch:9.1.0648: [security] double-free in dialog_changed()
Problem: [security] double-free in dialog_changed() (SuyueGuo) Solution: Only clear pointer b_sfname pointer, if it is different than the b_ffname pointer. Don't try to free b_fname, set it to NULL instead. fixes: vim/vim#15403 Github Advisory: https://github.com/vim/vim/security/advisories/GHSA-46pw-v7qw-xc2fb29f4abcd4
Co-authored-by: Christian Brabandt <cb@256bit.org> (cherry picked from commit6967c08840
)
This commit is contained in:
committed by
github-actions[bot]
parent
187c93d7e5
commit
05e72488b9
@ -226,9 +226,12 @@ void dialog_changed(buf_T *buf, bool checkall)
|
||||
|
||||
// restore to empty when write failed
|
||||
if (empty_bufname) {
|
||||
XFREE_CLEAR(buf->b_fname);
|
||||
XFREE_CLEAR(buf->b_ffname);
|
||||
// prevent double free
|
||||
if (buf->b_sfname != buf->b_ffname) {
|
||||
XFREE_CLEAR(buf->b_sfname);
|
||||
}
|
||||
buf->b_fname = NULL;
|
||||
XFREE_CLEAR(buf->b_ffname);
|
||||
unchanged(buf, true, false);
|
||||
}
|
||||
} else if (ret == VIM_NO) {
|
||||
|
@ -8,6 +8,7 @@ local eq = t.eq
|
||||
local eval = n.eval
|
||||
local exec = n.exec
|
||||
local feed = n.feed
|
||||
local pcall_err = t.pcall_err
|
||||
|
||||
before_each(clear)
|
||||
|
||||
@ -51,3 +52,14 @@ it('no crash when closing window with tag in loclist', function()
|
||||
eq(0, eval('bufexists(g:qf_bufnr)'))
|
||||
assert_alive()
|
||||
end)
|
||||
|
||||
it('no crash when writing "Untitled" file fails', function()
|
||||
t.mkdir('Untitled')
|
||||
finally(function()
|
||||
vim.uv.fs_rmdir('Untitled')
|
||||
end)
|
||||
feed('ifoobar')
|
||||
command('set bufhidden=unload')
|
||||
eq('Vim(enew):E502: "Untitled" is a directory', pcall_err(command, 'confirm enew'))
|
||||
assert_alive()
|
||||
end)
|
||||
|
BIN
test/old/testdir/crash/dialog_changed_uaf
Normal file
BIN
test/old/testdir/crash/dialog_changed_uaf
Normal file
Binary file not shown.
@ -196,6 +196,12 @@ func Test_crash1_3()
|
||||
call term_sendkeys(buf, args)
|
||||
call TermWait(buf, 50)
|
||||
|
||||
let file = 'crash/dialog_changed_uaf'
|
||||
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, 150)
|
||||
|
||||
" clean up
|
||||
exe buf .. "bw!"
|
||||
bw!
|
||||
|
Reference in New Issue
Block a user