Skip to content

Commit 35a9a00

Browse files
committed
patch 8.2.3428: using freed memory when replacing
Problem: Using freed memory when replacing. (Dhiraj Mishra) Solution: Get the line pointer after calling ins_copychar().
1 parent b3bf33a commit 35a9a00

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

src/normal.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5099,19 +5099,23 @@ nv_replace(cmdarg_T *cap)
50995099
{
51005100
/*
51015101
* Get ptr again, because u_save and/or showmatch() will have
5102-
* released the line. At the same time we let know that the
5103-
* line will be changed.
5102+
* released the line. This may also happen in ins_copychar().
5103+
* At the same time we let know that the line will be changed.
51045104
*/
5105-
ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum, TRUE);
51065105
if (cap->nchar == Ctrl_E || cap->nchar == Ctrl_Y)
51075106
{
51085107
int c = ins_copychar(curwin->w_cursor.lnum
51095108
+ (cap->nchar == Ctrl_Y ? -1 : 1));
5109+
5110+
ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum, TRUE);
51105111
if (c != NUL)
51115112
ptr[curwin->w_cursor.col] = c;
51125113
}
51135114
else
5115+
{
5116+
ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum, TRUE);
51145117
ptr[curwin->w_cursor.col] = cap->nchar;
5118+
}
51155119
if (p_sm && msg_silent == 0)
51165120
showmatch(cap->nchar);
51175121
++curwin->w_cursor.col;

src/testdir/test_edit.vim

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1895,4 +1895,16 @@ func Test_edit_revins()
18951895
bw!
18961896
endfunc
18971897

1898+
" Test for getting the character of the line below after "p"
1899+
func Test_edit_put_CTRL_E()
1900+
set encoding=latin1
1901+
new
1902+
let @" = ''
1903+
sil! norm orggRx
1904+
sil! norm pr
1905+
call assert_equal(['r', 'r'], getline(1, 2))
1906+
bwipe!
1907+
set encoding=utf-8
1908+
endfunc
1909+
18981910
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

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

756756
static int included_patches[] =
757757
{ /* Add new patch number below this line */
758+
/**/
759+
3428,
758760
/**/
759761
3427,
760762
/**/

0 commit comments

Comments
 (0)