]> granicus.if.org Git - vim/commitdiff
patch 8.1.2136: using freed memory with autocmd from fuzzer v8.1.2136
authorBram Moolenaar <Bram@vim.org>
Fri, 11 Oct 2019 19:19:13 +0000 (21:19 +0200)
committerBram Moolenaar <Bram@vim.org>
Fri, 11 Oct 2019 19:19:13 +0000 (21:19 +0200)
Problem:    using freed memory with autocmd from fuzzer. (Dhiraj Mishra,
            Dominique Pelle)
Solution:   Avoid using "wp" after autocommands. (closes #5041)

src/testdir/test_autocmd.vim
src/version.c
src/window.c

index fe77bf578667bc0b57d13a1f915aaf4961e848ee..1e53fe4639489e14540b449712088b91fd47cb86 100644 (file)
@@ -2288,3 +2288,11 @@ func Test_autocmd_CmdWinEnter()
   call StopVimInTerminal(buf)
   call delete(filename)
 endfunc
+
+func Test_autocmd_was_using_freed_memory()
+  pedit xx
+  n x
+  au WinEnter * quit
+  split
+  au! WinEnter
+endfunc
index f22db55478de731f8558e5bab165e5223604913e..46bd1b19c69666aff808456250fa59a5363a0982 100644 (file)
@@ -753,6 +753,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2136,
 /**/
     2135,
 /**/
index 0fda9f05c666485d2f43448ed0a8a9960584e4e3..fb8a5a7ede8ffeb83c33e2be24d89b5715e51eda 100644 (file)
@@ -4641,6 +4641,7 @@ win_enter_ext(
 #ifdef FEAT_JOB_CHANNEL
     entering_window(curwin);
 #endif
+    // Careful: autocommands may close the window and make "wp" invalid
     if (trigger_new_autocmds)
        apply_autocmds(EVENT_WINNEW, NULL, NULL, FALSE, curbuf);
     if (trigger_enter_autocmds)
@@ -4655,7 +4656,7 @@ win_enter_ext(
 #endif
     curwin->w_redr_status = TRUE;
 #ifdef FEAT_TERMINAL
-    if (bt_terminal(wp->w_buffer))
+    if (bt_terminal(curwin->w_buffer))
        // terminal is likely in another mode
        redraw_mode = TRUE;
 #endif