Skip to content

Commit

Permalink
patch 8.2.3487: illegal memory access if buffer name is very long
Browse files Browse the repository at this point in the history
Problem:    Illegal memory access if buffer name is very long.
Solution:   Make sure not to go over the end of the buffer.
  • Loading branch information
brammool committed Oct 8, 2021
1 parent cce81e9 commit 826bfe4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/drawscreen.c
Expand Up @@ -464,13 +464,13 @@ win_redr_status(win_T *wp, int ignore_pum UNUSED)
*(p + len++) = ' ';
if (bt_help(wp->w_buffer))
{
STRCPY(p + len, _("[Help]"));
vim_snprintf((char *)p + len, MAXPATHL - len, "%s", _("[Help]"));
len += (int)STRLEN(p + len);
}
#ifdef FEAT_QUICKFIX
if (wp->w_p_pvw)
{
STRCPY(p + len, _("[Preview]"));
vim_snprintf((char *)p + len, MAXPATHL - len, "%s", _("[Preview]"));
len += (int)STRLEN(p + len);
}
#endif
Expand All @@ -480,12 +480,12 @@ win_redr_status(win_T *wp, int ignore_pum UNUSED)
#endif
)
{
STRCPY(p + len, "[+]");
len += 3;
vim_snprintf((char *)p + len, MAXPATHL - len, "%s", "[+]");
len += (int)STRLEN(p + len);
}
if (wp->w_buffer->b_p_ro)
{
STRCPY(p + len, _("[RO]"));
vim_snprintf((char *)p + len, MAXPATHL - len, "%s", _("[RO]"));
len += (int)STRLEN(p + len);
}

Expand Down
10 changes: 10 additions & 0 deletions src/testdir/test_statusline.vim
Expand Up @@ -522,4 +522,14 @@ func Test_statusline_mbyte_fillchar()
%bw!
endfunc

" Used to write beyond allocated memory. This assumes MAXPATHL is 4096 bytes.
func Test_statusline_verylong_filename()
let fname = repeat('x', 4090)
exe "new " .. fname
set buftype=help
set previewwindow
redraw
bwipe!
endfunc

" vim: shiftwidth=2 sts=2 expandtab
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -757,6 +757,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
3487,
/**/
3486,
/**/
Expand Down

0 comments on commit 826bfe4

Please sign in to comment.