Skip to content

Commit a493b65

Browse files
brandon1024brammool
authored andcommitted
patch 8.2.4419: illegal memory access when using 20 highlights
Problem: Illegal memory access when using exactly 20 highlights. Solution: Add one more item in the array. (Brandon Richardson, closes #9800)
1 parent 5921aeb commit a493b65

3 files changed

Lines changed: 22 additions & 4 deletions

File tree

src/buffer.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4170,8 +4170,11 @@ build_stl_str_hl(
41704170
{
41714171
stl_items = ALLOC_MULT(stl_item_T, stl_items_len);
41724172
stl_groupitem = ALLOC_MULT(int, stl_items_len);
4173-
stl_hltab = ALLOC_MULT(stl_hlrec_T, stl_items_len);
4174-
stl_tabtab = ALLOC_MULT(stl_hlrec_T, stl_items_len);
4173+
4174+
// Allocate one more, because the last element is used to indicate the
4175+
// end of the list.
4176+
stl_hltab = ALLOC_MULT(stl_hlrec_T, stl_items_len + 1);
4177+
stl_tabtab = ALLOC_MULT(stl_hlrec_T, stl_items_len + 1);
41754178
}
41764179

41774180
#ifdef FEAT_EVAL
@@ -4251,11 +4254,13 @@ build_stl_str_hl(
42514254
if (new_groupitem == NULL)
42524255
break;
42534256
stl_groupitem = new_groupitem;
4254-
new_hlrec = vim_realloc(stl_hltab, sizeof(stl_hlrec_T) * new_len);
4257+
new_hlrec = vim_realloc(stl_hltab,
4258+
sizeof(stl_hlrec_T) * (new_len + 1));
42554259
if (new_hlrec == NULL)
42564260
break;
42574261
stl_hltab = new_hlrec;
4258-
new_hlrec = vim_realloc(stl_tabtab, sizeof(stl_hlrec_T) * new_len);
4262+
new_hlrec = vim_realloc(stl_tabtab,
4263+
sizeof(stl_hlrec_T) * (new_len + 1));
42594264
if (new_hlrec == NULL)
42604265
break;
42614266
stl_tabtab = new_hlrec;

src/testdir/test_tabline.vim

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,17 @@ func Test_tabline_empty_group()
134134
set tabline=
135135
endfunc
136136

137+
" When there are exactly 20 tabline format items (the exact size of the
138+
" initial tabline items array), test that we don't write beyond the size
139+
" of the array.
140+
func Test_tabline_20_format_items_no_overrun()
141+
set showtabline=2
137142

143+
let tabline = repeat('%#StatColorHi2#', 20)
144+
let &tabline = tabline
145+
redrawtabline
146+
147+
set showtabline& tabline&
148+
endfunc
138149

139150
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

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

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
4419,
753755
/**/
754756
4418,
755757
/**/

0 commit comments

Comments
 (0)