mirror of
https://github.com/neovim/neovim
synced 2025-07-15 16:51:49 +00:00
vim-patch:9.1.0647: [security] use-after-free in tagstack_clear_entry
Problem: [security] use-after-free in tagstack_clear_entry (Suyue Guo ) Solution: Instead of manually calling vim_free() on each of the tagstack entries, let's use tagstack_clear_entry(), which will also free the stack, but using the VIM_CLEAR macro, which prevents a use-after-free by setting those pointers to NULL This addresses CVE-2024-41957 Github advisory: https://github.com/vim/vim/security/advisories/GHSA-f9cr-gv85-hcr48a0bbe7b8a
Co-authored-by: Christian Brabandt <cb@256bit.org> (cherry picked from commit6af359ef4c
)
This commit is contained in:
@ -3183,7 +3183,7 @@ static int find_extra(char **pp)
|
||||
//
|
||||
// Free a single entry in a tag stack
|
||||
//
|
||||
static void tagstack_clear_entry(taggy_T *item)
|
||||
void tagstack_clear_entry(taggy_T *item)
|
||||
{
|
||||
XFREE_CLEAR(item->tagname);
|
||||
XFREE_CLEAR(item->user_data);
|
||||
|
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "nvim/buffer_defs.h" // IWYU pragma: keep
|
||||
#include "nvim/eval/typval_defs.h" // IWYU pragma: keep
|
||||
#include "nvim/ex_cmds_defs.h" // IWYU pragma: keep
|
||||
#include "nvim/option_defs.h" // IWYU pragma: keep
|
||||
|
@ -72,6 +72,7 @@
|
||||
#include "nvim/statusline.h"
|
||||
#include "nvim/strings.h"
|
||||
#include "nvim/syntax.h"
|
||||
#include "nvim/tag.h"
|
||||
#include "nvim/terminal.h"
|
||||
#include "nvim/types_defs.h"
|
||||
#include "nvim/ui.h"
|
||||
@ -5219,8 +5220,7 @@ void win_free(win_T *wp, tabpage_T *tp)
|
||||
xfree(wp->w_lines);
|
||||
|
||||
for (int i = 0; i < wp->w_tagstacklen; i++) {
|
||||
xfree(wp->w_tagstack[i].tagname);
|
||||
xfree(wp->w_tagstack[i].user_data);
|
||||
tagstack_clear_entry(&wp->w_tagstack[i]);
|
||||
}
|
||||
|
||||
xfree(wp->w_localdir);
|
||||
|
@ -1,8 +1,12 @@
|
||||
local t = require('test.testutil')
|
||||
local n = require('test.functional.testnvim')()
|
||||
|
||||
local assert_alive = n.assert_alive
|
||||
local clear = n.clear
|
||||
local command = n.command
|
||||
local eq = t.eq
|
||||
local eval = n.eval
|
||||
local exec = n.exec
|
||||
local feed = n.feed
|
||||
|
||||
before_each(clear)
|
||||
@ -32,3 +36,18 @@ it('no crash with very long option error message', function()
|
||||
pcall(command, 'source test/old/testdir/crash/poc_did_set_langmap')
|
||||
assert_alive()
|
||||
end)
|
||||
|
||||
it('no crash when closing window with tag in loclist', function()
|
||||
exec([[
|
||||
new
|
||||
lexpr ['foo']
|
||||
lopen
|
||||
let g:qf_bufnr = bufnr()
|
||||
lclose
|
||||
call settagstack(1, #{items: [#{tagname: 'foo', from: [g:qf_bufnr, 1, 1, 0]}]})
|
||||
]])
|
||||
eq(1, eval('bufexists(g:qf_bufnr)'))
|
||||
command('1close')
|
||||
eq(0, eval('bufexists(g:qf_bufnr)'))
|
||||
assert_alive()
|
||||
end)
|
||||
|
BIN
test/old/testdir/crash/double_free
Normal file
BIN
test/old/testdir/crash/double_free
Normal file
Binary file not shown.
@ -190,6 +190,12 @@ func Test_crash1_3()
|
||||
call term_sendkeys(buf, args)
|
||||
call TermWait(buf, 150)
|
||||
|
||||
let file = 'crash/double_free'
|
||||
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)
|
||||
|
||||
" clean up
|
||||
exe buf .. "bw!"
|
||||
bw!
|
||||
|
Reference in New Issue
Block a user