Skip to content

Commit 761ea77

Browse files
girishjizeertzjqh-east
authored andcommitted
patch 9.1.1609: complete: Heap-buffer overflow with complete function
Problem: complete: Heap-buffer overflow with complete function (zeertzjq) Solution: Do not let startcol become negative (Girish Palya). fixes: #17907 closes: #17934 Co-authored-by: zeertzjq <zeertzjq@outlook.com> Co-authored-by: Hirohito Higashi <h.east.727@gmail.com> Signed-off-by: Girish Palya <girishji@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent b89ff6c commit 761ea77

3 files changed

Lines changed: 34 additions & 5 deletions

File tree

src/insexpand.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,6 @@ typedef struct cpt_source_T
247247
#endif
248248
} cpt_source_T;
249249

250-
#define STARTCOL_NONE -9
251250
static cpt_source_T *cpt_sources_array; // Pointer to the array of completion sources
252251
static int cpt_sources_count; // Total number of completion sources specified in the 'cpt' option
253252
static int cpt_sources_index = -1; // Index of the current completion source being expanded
@@ -5368,10 +5367,12 @@ prepare_cpt_compl_funcs(void)
53685367
else
53695368
startcol = -2;
53705369
}
5370+
else if (startcol < 0 || startcol > curwin->w_cursor.col)
5371+
startcol = curwin->w_cursor.col;
53715372
cpt_sources_array[idx].cs_startcol = startcol;
53725373
}
53735374
else
5374-
cpt_sources_array[idx].cs_startcol = STARTCOL_NONE;
5375+
cpt_sources_array[idx].cs_startcol = -3;
53755376

53765377
(void)copy_option_part(&p, IObuff, IOSIZE, ","); // Advance p
53775378
idx++;
@@ -7495,16 +7496,15 @@ cpt_compl_refresh(void)
74957496
else
74967497
startcol = -2;
74977498
}
7499+
else if (startcol < 0 || startcol > curwin->w_cursor.col)
7500+
startcol = curwin->w_cursor.col;
74987501
cpt_sources_array[cpt_sources_index].cs_startcol = startcol;
74997502
if (ret == OK)
75007503
{
75017504
compl_source_start_timer(cpt_sources_index);
75027505
get_cpt_func_completion_matches(cb);
75037506
}
75047507
}
7505-
else
7506-
cpt_sources_array[cpt_sources_index].cs_startcol
7507-
= STARTCOL_NONE;
75087508
}
75097509

75107510
(void)copy_option_part(&p, IObuff, IOSIZE, ","); // Advance p

src/testdir/test_ins_complete.vim

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5383,4 +5383,31 @@ func Test_scriplocal_autoload_func()
53835383
let &rtp = save_rtp
53845384
endfunc
53855385

5386+
" Issue #17907
5387+
func Test_omni_start_invalid_col()
5388+
func OmniFunc(startcol, findstart, base)
5389+
if a:findstart
5390+
return a:startcol
5391+
else
5392+
return ['foo', 'foobar']
5393+
endif
5394+
endfunc
5395+
5396+
new
5397+
set complete=o
5398+
set omnifunc=funcref('OmniFunc',\ [-1])
5399+
call setline(1, ['baz '])
5400+
call feedkeys("A\<C-N>\<Esc>0", 'tx!')
5401+
call assert_equal('baz foo', getline(1))
5402+
5403+
set omnifunc=funcref('OmniFunc',\ [1000])
5404+
call setline(1, ['bar '])
5405+
call feedkeys("A\<C-N>\<Esc>0", 'tx!')
5406+
call assert_equal('bar foo', getline(1))
5407+
bw!
5408+
5409+
delfunc OmniFunc
5410+
set omnifunc& complete&
5411+
endfunc
5412+
53865413
" vim: shiftwidth=2 sts=2 expandtab nofoldenable

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,8 @@ static char *(features[]) =
719719

720720
static int included_patches[] =
721721
{ /* Add new patch number below this line */
722+
/**/
723+
1609,
722724
/**/
723725
1608,
724726
/**/

0 commit comments

Comments
 (0)