Skip to content

Commit c0f0e23

Browse files
committed
patch 9.1.1115: [security]: use-after-free in str_to_reg()
Problem: [security]: use-after-free in str_to_reg() (fizz-is-on-the-way) Solution: when redirecting the :display command, check that one does not output to the register being displayed Github Advisory: GHSA-63p5-mwg2-787v Signed-off-by: Christian Brabandt <[email protected]>
1 parent 27822a0 commit c0f0e23

3 files changed

Lines changed: 24 additions & 1 deletion

File tree

src/register.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2420,7 +2420,8 @@ ex_display(exarg_T *eap)
24202420

24212421
#ifdef FEAT_EVAL
24222422
if (name == MB_TOLOWER(redir_reg)
2423-
|| (redir_reg == '"' && yb == y_previous))
2423+
|| (vim_strchr((char_u *)"\"*+", redir_reg) != NULL &&
2424+
(yb == y_previous || yb == &y_regs[0])))
24242425
continue; // do not list register being written to, the
24252426
// pointer can be freed
24262427
#endif

src/testdir/test_registers.vim

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,4 +1102,24 @@ func Test_clipboard_regs_not_working2()
11021102
let $DISPLAY=display
11031103
endfunc
11041104

1105+
" This caused use-after-free
1106+
func Test_register_redir_display()
1107+
" don't touch the clipboard, so only perform this, when the clipboard is not working
1108+
if has("clipboard_working")
1109+
throw "Skipped: skip touching the clipboard register!"
1110+
endif
1111+
let @"=''
1112+
redir @+>
1113+
disp +"
1114+
redir END
1115+
call assert_equal("\nType Name Content", getreg('+'))
1116+
let a = [getreg('1'), getregtype('1')]
1117+
let @1='register 1'
1118+
redir @+
1119+
disp 1
1120+
redir END
1121+
call assert_equal("register 1", getreg('1'))
1122+
call setreg(1, a[0], a[1])
1123+
endfunc
1124+
11051125
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

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

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
1115,
707709
/**/
708710
1114,
709711
/**/

0 commit comments

Comments
 (0)