0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

patch 9.1.0254: [security]: Heap buffer overflow when calling complete_add() in 'cfu'

Problem:  [security]: Heap buffer overflow when calling complete_add()
          in the first call of 'completefunc'
Solution: Call check_cursor() after calling 'completefunc' (zeertzjq)

closes: #14391

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
zeertzjq
2024-04-02 19:01:14 +02:00
committed by Christian Brabandt
parent 6c9f4f98f1
commit 0a419e07a7
3 changed files with 26 additions and 0 deletions

View File

@@ -2741,6 +2741,7 @@ expand_by_function(int type, char_u *base)
--textlock; --textlock;
curwin->w_cursor = pos; // restore the cursor position curwin->w_cursor = pos; // restore the cursor position
check_cursor(); // make sure cursor position is valid, just in case
validate_cursor(); validate_cursor();
if (!EQUAL_POS(curwin->w_cursor, pos)) if (!EQUAL_POS(curwin->w_cursor, pos))
{ {
@@ -4606,6 +4607,7 @@ get_userdefined_compl_info(colnr_T curs_col UNUSED)
State = save_State; State = save_State;
curwin->w_cursor = pos; // restore the cursor position curwin->w_cursor = pos; // restore the cursor position
check_cursor(); // make sure cursor position is valid, just in case
validate_cursor(); validate_cursor();
if (!EQUAL_POS(curwin->w_cursor, pos)) if (!EQUAL_POS(curwin->w_cursor, pos))
{ {

View File

@@ -2429,4 +2429,26 @@ func Test_complete_changed_complete_info()
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
endfunc endfunc
func Test_completefunc_first_call_complete_add()
new
func Complete(findstart, base) abort
if a:findstart
let col = col('.')
call complete_add('#')
return col - 1
else
return []
endif
endfunc
set completeopt=longest completefunc=Complete
" This used to cause heap-buffer-overflow
call assert_fails('call feedkeys("ifoo#\<C-X>\<C-U>", "xt")', 'E840:')
delfunc Complete
set completeopt& completefunc&
bwipe!
endfunc
" vim: shiftwidth=2 sts=2 expandtab nofoldenable " vim: shiftwidth=2 sts=2 expandtab nofoldenable

View File

@@ -704,6 +704,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
254,
/**/ /**/
253, 253,
/**/ /**/