changeset 28475:a7556b47ff09 v8.2.4762

patch 8.2.4762: using freed memory using synstack() and synID() in WinEnter Commit: https://github.com/vim/vim/commit/ca7e86c23789eb0ed8f6400f25ea9e0e1036f9fc Author: zeertzjq <zeertzjq@outlook.com> Date: Sat Apr 16 16:49:24 2022 +0100 patch 8.2.4762: using freed memory using synstack() and synID() in WinEnter Problem: Using freed memory when using synstack() and synID() in WinEnter. Solution: Check using the syntax window. (closes https://github.com/vim/vim/issues/10204)
author Bram Moolenaar <Bram@vim.org>
date Sat, 16 Apr 2022 18:00:04 +0200
parents c2b4fd1c8441
children 345b77f77001
files src/syntax.c src/testdir/test_syntax.vim src/version.c
diffstat 3 files changed, 18 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -6486,8 +6486,9 @@ syn_get_id(
     int		keep_state)  // keep state of char at "col"
 {
     // When the position is not after the current position and in the same
-    // line of the same buffer, need to restart parsing.
-    if (wp->w_buffer != syn_buf
+    // line of the same window with the same buffer, need to restart parsing.
+    if (wp != syn_win
+	    || wp->w_buffer != syn_buf
 	    || lnum != current_lnum
 	    || col < current_col)
 	syntax_start(wp, lnum);
--- a/src/testdir/test_syntax.vim
+++ b/src/testdir/test_syntax.vim
@@ -956,5 +956,18 @@ func Test_syn_include_contains_TOP()
   bw!
 endfunc
 
+" This was using freed memory
+func Test_WinEnter_synstack_synID()
+  autocmd WinEnter * call synstack(line("."), col("."))
+  autocmd WinEnter * call synID(line('.'), col('.') - 1, 1)
+  call setline(1, 'aaaaa')
+  normal! $
+  new
+  close
+
+  au! WinEnter
+  bw!
+endfunc
+
 
 " vim: shiftwidth=2 sts=2 expandtab
--- 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 */
 /**/
+    4762,
+/**/
     4761,
 /**/
     4760,