]> git.feebdaed.xyz Git - 0xmirror/vim.git/commitdiff
patch 9.1.2023: [security]: Use-after-free in alist_add() with nasty autocmd
authorChristian Brabandt <cb@256bit.org>
Sat, 27 Dec 2025 14:10:37 +0000 (14:10 +0000)
committerChristian Brabandt <cb@256bit.org>
Sat, 27 Dec 2025 14:10:37 +0000 (14:10 +0000)
Problem:  A BufAdd autocommand may cause alist_add() to use freed
          memory, this is caused by the w_locked variable unset too
          early (henices)
Solution: in trigger_undo_ftplugin() only set w_locked to false, if it
          was false when calling the function.

related: v9.1.0678
closes: #19023

Signed-off-by: Christian Brabandt <cb@256bit.org>
src/buffer.c
src/testdir/test_arglist.vim
src/version.c

index 0ed61a703265524327b2e1a5e3c27827c9766ab9..52aa13de210dfb32240f2574e7d0b6fac0e8d8a2 100644 (file)
@@ -75,6 +75,7 @@ static garray_T buf_reuse = GA_EMPTY; // file numbers to recycle
     static void
 trigger_undo_ftplugin(buf_T *buf, win_T *win)
 {
+    int win_was_locked = win->w_locked;
     window_layout_lock();
     buf->b_locked++;
     win->w_locked = TRUE;
@@ -82,7 +83,7 @@ trigger_undo_ftplugin(buf_T *buf, win_T *win)
     do_cmdline_cmd((char_u*)"if exists('b:undo_ftplugin') | :legacy :exe \
            b:undo_ftplugin | endif");
     buf->b_locked--;
-    win->w_locked = FALSE;
+    win->w_locked = win_was_locked;
     window_layout_unlock();
 }
 
index 2a76ca6515bd062b1b725b4e9299eba60edfc0a5..ed3ea718c210ccecd74b97843eef6f4d1575e645 100644 (file)
@@ -772,7 +772,6 @@ func Test_crash_arglist_uaf()
   "%argdelete
   new one
   au BufAdd XUAFlocal :bw
-  "call assert_fails(':arglocal XUAFlocal', 'E163:')
   arglocal XUAFlocal
   au! BufAdd
   bw! XUAFlocal
@@ -788,4 +787,15 @@ func Test_crash_arglist_uaf()
   au! BufAdd
 endfunc
 
+" This was using freed memory again
+func Test_crash_arglist_uaf2()
+  new
+  au BufAdd XUAFlocal :bw
+  arglocal XUAFlocal
+  redraw!
+  put ='abc'
+  2#
+  au! BufAdd
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index c88bff30ab5d474916455fa9074221fce5ba934c..fad0bdd585f8e8a7cbf4f76c54666e518cad092c 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2023,
 /**/
     2022,
 /**/