summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-05-18 16:29:08 +0100
committerBram Moolenaar <Bram@vim.org>2022-05-18 16:29:08 +0100
commit28d032cc688ccfda18c5bbcab8b50aba6e18cde5 (patch)
treebbfa3bdb52dd1dab35cb36c9525d6b60a172d211
parent360da40b47a84ee8586c3b5d062f8c64a2ac9cc6 (diff)
downloadvim-git-28d032cc688ccfda18c5bbcab8b50aba6e18cde5.tar.gz
patch 8.2.4979: accessing freed memory when line is flushedv8.2.4979
Problem: Accessing freed memory when line is flushed. Solution: Make a copy of the pattern to search for.
-rw-r--r--src/testdir/test_tagjump.vim9
-rw-r--r--src/version.c2
-rw-r--r--src/window.c7
3 files changed, 18 insertions, 0 deletions
diff --git a/src/testdir/test_tagjump.vim b/src/testdir/test_tagjump.vim
index 97670bcfc..8b19c634d 100644
--- a/src/testdir/test_tagjump.vim
+++ b/src/testdir/test_tagjump.vim
@@ -1392,6 +1392,15 @@ func Test_macro_search()
close!
endfunc
+func Test_define_search()
+ " this was accessing freed memory
+ new
+ call setline(1, ['first line', '', '#define something 0'])
+ sil norm o0
+ sil! norm 
+ bwipe!
+endfunc
+
" Test for [*, [/, ]* and ]/
func Test_comment_search()
new
diff --git a/src/version.c b/src/version.c
index 854de4597..37e3d80f8 100644
--- a/src/version.c
+++ b/src/version.c
@@ -747,6 +747,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 4979,
+/**/
4978,
/**/
4977,
diff --git a/src/window.c b/src/window.c
index fca0eea32..984fb4631 100644
--- a/src/window.c
+++ b/src/window.c
@@ -579,9 +579,16 @@ wingotofile:
CHECK_CMDWIN;
if ((len = find_ident_under_cursor(&ptr, FIND_IDENT)) == 0)
break;
+
+ // Make a copy, if the line was changed it will be freed.
+ ptr = vim_strnsave(ptr, len);
+ if (ptr == NULL)
+ break;
+
find_pattern_in_path(ptr, 0, len, TRUE,
Prenum == 0 ? TRUE : FALSE, type,
Prenum1, ACTION_SPLIT, (linenr_T)1, (linenr_T)MAXLNUM);
+ vim_free(ptr);
curwin->w_set_curswant = TRUE;
break;
#endif