Skip to content

Commit 9266a2a

Browse files
committed
patch 9.1.2023: [security]: Use-after-free in alist_add() with nasty autocmd
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>
1 parent 1ff2239 commit 9266a2a

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

src/buffer.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,15 @@ static garray_T buf_reuse = GA_EMPTY; // file numbers to recycle
7575
static void
7676
trigger_undo_ftplugin(buf_T *buf, win_T *win)
7777
{
78+
int win_was_locked = win->w_locked;
7879
window_layout_lock();
7980
buf->b_locked++;
8081
win->w_locked = TRUE;
8182
// b:undo_ftplugin may be set, undo it
8283
do_cmdline_cmd((char_u*)"if exists('b:undo_ftplugin') | :legacy :exe \
8384
b:undo_ftplugin | endif");
8485
buf->b_locked--;
85-
win->w_locked = FALSE;
86+
win->w_locked = win_was_locked;
8687
window_layout_unlock();
8788
}
8889

src/testdir/test_arglist.vim

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,6 @@ func Test_crash_arglist_uaf()
772772
"%argdelete
773773
new one
774774
au BufAdd XUAFlocal :bw
775-
"call assert_fails(':arglocal XUAFlocal', 'E163:')
776775
arglocal XUAFlocal
777776
au! BufAdd
778777
bw! XUAFlocal
@@ -788,4 +787,15 @@ func Test_crash_arglist_uaf()
788787
au! BufAdd
789788
endfunc
790789

790+
" This was using freed memory again
791+
func Test_crash_arglist_uaf2()
792+
new
793+
au BufAdd XUAFlocal :bw
794+
arglocal XUAFlocal
795+
redraw!
796+
put ='abc'
797+
2#
798+
au! BufAdd
799+
endfunc
800+
791801
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,8 @@ static char *(features[]) =
734734

735735
static int included_patches[] =
736736
{ /* Add new patch number below this line */
737+
/**/
738+
2023,
737739
/**/
738740
2022,
739741
/**/

0 commit comments

Comments
 (0)