Skip to content
Permalink
Browse files Browse the repository at this point in the history
patch 9.0.1376: accessing invalid memory with put in Visual block mode
Problem:    Accessing invalid memory with put in Visual block mode.
Solution:   Adjust the cursor column if needed.
  • Loading branch information
brammool committed Mar 3, 2023
1 parent f77a7f7 commit 1c73b65
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/register.c
Expand Up @@ -1928,7 +1928,7 @@ do_put(
ptr += yanklen;

// insert block's trailing spaces only if there's text behind
if ((j < count - 1 || !shortline) && spaces)
if ((j < count - 1 || !shortline) && spaces > 0)
{
vim_memset(ptr, ' ', (size_t)spaces);
ptr += spaces;
Expand Down Expand Up @@ -2284,6 +2284,15 @@ do_put(
msgmore(nr_lines);
curwin->w_set_curswant = TRUE;

// Make sure the cursor is not after the NUL.
int len = (int)STRLEN(ml_get_curline());
if (curwin->w_cursor.col > len)
{
if (cur_ve_flags == VE_ALL)
curwin->w_cursor.coladd = curwin->w_cursor.col - len;
curwin->w_cursor.col = len;
}

end:
if (cmdmod.cmod_flags & CMOD_LOCKMARKS)
{
Expand Down
11 changes: 11 additions & 0 deletions src/testdir/test_put.vim
Expand Up @@ -231,5 +231,16 @@ func Test_put_visual_mode()
set selection&
endfunc

func Test_put_visual_block_mode()
enew
exe "norm 0R\<CR>\<C-C>V"
sil exe "norm \<C-V>c \<MiddleDrag>"
set ve=all
sil norm vz=p

bwipe!
set ve=
endfunc


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

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

0 comments on commit 1c73b65

Please sign in to comment.