]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core.git/blob - meta/recipes-support/vim/files/0002-patch-8.2.3428-using-freed-memory-when-replacing.patch
ecfae0301ea3626be7227ffbd1d291086cd1eaa3
[thirdparty/openembedded/openembedded-core.git] / meta / recipes-support / vim / files / 0002-patch-8.2.3428-using-freed-memory-when-replacing.patch
1 CVE: CVE-2021-3796
2 Upstream-Status: Backport
3 Signed-off-by: Ross Burton <ross.burton@arm.com>
4
5 From 1160e5f74b229336502fc376416f21108d36cfc2 Mon Sep 17 00:00:00 2001
6 From: Bram Moolenaar <Bram@vim.org>
7 Date: Sat, 11 Sep 2021 21:14:20 +0200
8 Subject: [PATCH] patch 8.2.3428: using freed memory when replacing
9
10 Problem: Using freed memory when replacing. (Dhiraj Mishra)
11 Solution: Get the line pointer after calling ins_copychar().
12 ---
13 src/normal.c | 10 +++++++---
14 src/testdir/test_edit.vim | 14 ++++++++++++++
15 src/version.c | 2 ++
16 3 files changed, 23 insertions(+), 3 deletions(-)
17
18 diff --git a/src/normal.c b/src/normal.c
19 index c4963e621..d6333b948 100644
20 --- a/src/normal.c
21 +++ b/src/normal.c
22 @@ -5009,19 +5009,23 @@ nv_replace(cmdarg_T *cap)
23 {
24 /*
25 * Get ptr again, because u_save and/or showmatch() will have
26 - * released the line. At the same time we let know that the
27 - * line will be changed.
28 + * released the line. This may also happen in ins_copychar().
29 + * At the same time we let know that the line will be changed.
30 */
31 - ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum, TRUE);
32 if (cap->nchar == Ctrl_E || cap->nchar == Ctrl_Y)
33 {
34 int c = ins_copychar(curwin->w_cursor.lnum
35 + (cap->nchar == Ctrl_Y ? -1 : 1));
36 +
37 + ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum, TRUE);
38 if (c != NUL)
39 ptr[curwin->w_cursor.col] = c;
40 }
41 else
42 + {
43 + ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum, TRUE);
44 ptr[curwin->w_cursor.col] = cap->nchar;
45 + }
46 if (p_sm && msg_silent == 0)
47 showmatch(cap->nchar);
48 ++curwin->w_cursor.col;
49 diff --git a/src/testdir/test_edit.vim b/src/testdir/test_edit.vim
50 index 4e29e7fe1..f94e6c181 100644
51 --- a/src/testdir/test_edit.vim
52 +++ b/src/testdir/test_edit.vim
53 @@ -1519,3 +1519,17 @@ func Test_edit_noesckeys()
54 bwipe!
55 set esckeys
56 endfunc
57 +
58 +" Test for getting the character of the line below after "p"
59 +func Test_edit_put_CTRL_E()
60 + set encoding=latin1
61 + new
62 + let @" = ''
63 + sil! norm or\ 3ggRx
64 + sil! norm pr\ 5
65 + call assert_equal(['r', 'r'], getline(1, 2))
66 + bwipe!
67 + set encoding=utf-8
68 +endfunc
69 +
70 +" vim: shiftwidth=2 sts=2 expandtab
71 diff --git a/src/version.c b/src/version.c
72 index 85bdfc601..1046993d6 100644
73 --- a/src/version.c
74 +++ b/src/version.c
75 @@ -742,6 +742,8 @@ static char *(features[]) =
76
77 static int included_patches[] =
78 { /* Add new patch number below this line */
79 +/**/
80 + 3428,
81 /**/
82 3409,
83 /**/