Skip to content

Commit

Permalink
patch 8.2.4218: illegal memory access with bracketed paste in Ex mode
Browse files Browse the repository at this point in the history
Problem:    Illegal memory access with bracketed paste in Ex mode.
Solution:   Reserve space for the trailing NUL.
  • Loading branch information
brammool committed Jan 25, 2022
1 parent 8d02ce1 commit 806d037
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/edit.c
Expand Up @@ -4452,7 +4452,8 @@ bracketed_paste(paste_mode_T mode, int drop, garray_T *gap)
break;

case PASTE_EX:
if (gap != NULL && ga_grow(gap, idx) == OK)
// add one for the NUL that is going to be appended
if (gap != NULL && ga_grow(gap, idx + 1) == OK)
{
mch_memmove((char *)gap->ga_data + gap->ga_len,
buf, (size_t)idx);
Expand Down
3 changes: 3 additions & 0 deletions src/testdir/test_paste.vim
Expand Up @@ -90,6 +90,9 @@ func Test_paste_ex_mode()
unlet! foo
call feedkeys("Qlet foo=\"\<Esc>[200~foo\<CR>bar\<Esc>[201~\"\<CR>vi\<CR>", 'xt')
call assert_equal("foo\rbar", foo)

" pasting more than 40 bytes
exe "norm Q\<PasteStart>0000000000000000000000000000000000000000000000000000000000000000000000\<C-C>"
endfunc

func Test_paste_onechar()
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -750,6 +750,8 @@ static char *(features[]) =

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

0 comments on commit 806d037

Please sign in to comment.