Skip to content

Commit

Permalink
patch 9.0.1873: [security] heap-buffer-overflow in vim_regsub_both
Browse files Browse the repository at this point in the history
Problem:  heap-buffer-overflow in vim_regsub_both
Solution: Disallow exchanging windows when textlock is active

Signed-off-by: Christian Brabandt <cb@256bit.org>
  • Loading branch information
chrisbra committed Sep 5, 2023
1 parent d2a08ba commit f6d28fe
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/ex_cmds.c
Expand Up @@ -4519,6 +4519,9 @@ ex_substitute(exarg_T *eap)
{
nmatch = curbuf->b_ml.ml_line_count - sub_firstlnum + 1;
skip_match = TRUE;
// safety check
if (nmatch < 0)
goto skip;
}

// Need room for:
Expand Down
Binary file added src/testdir/crash/vim_regsub_both_poc
Binary file not shown.
9 changes: 9 additions & 0 deletions src/testdir/test_crash.vim
Expand Up @@ -46,6 +46,7 @@ func Test_crash1()

let file = 'crash/poc_tagfunc.vim'
let args = printf(cmn_args, vim, file)
" using || because this poc causes vim to exit with exitstatus != 0
call term_sendkeys(buf, args ..
\ ' || echo "crash 5: [OK]" >> X_crash1_result.txt' .. "\<cr>")

Expand All @@ -59,6 +60,13 @@ func Test_crash1()
call delete('X')
call TermWait(buf, 3000)

let file = 'crash/vim_regsub_both_poc'
let args = printf(cmn_args, vim, file)
" using || because this poc causes vim to exit with exitstatus != 0

This comment has been minimized.

Copy link
@cvwillegen

cvwillegen Sep 5, 2023

Contributor

... but you use && in the line below it.

This comment has been minimized.

Copy link
@chrisbra

chrisbra Sep 5, 2023

Author Member

that is true. For that we don't need it :(

This comment has been minimized.

Copy link
@chrisbra

chrisbra Sep 5, 2023

Author Member

I'll fix in a second

call term_sendkeys(buf, args ..
\ ' && echo "crash 7: [OK]" >> X_crash1_result.txt' .. "\<cr>")
call TermWait(buf, 1000)

" clean up
exe buf .. "bw!"

Expand All @@ -71,6 +79,7 @@ func Test_crash1()
\ 'crash 4: [OK]',
\ 'crash 5: [OK]',
\ 'crash 6: [OK]',
\ 'crash 7: [OK]',
\ ]

call assert_equal(expected, getline(1, '$'))
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -699,6 +699,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1873,
/**/
1872,
/**/
Expand Down
5 changes: 5 additions & 0 deletions src/window.c
Expand Up @@ -1733,6 +1733,11 @@ win_exchange(long Prenum)
beep_flush();
return;
}
if (text_or_buf_locked())
{
beep_flush();
return;
}

#ifdef FEAT_GUI
need_mouse_correct = TRUE;
Expand Down

0 comments on commit f6d28fe

Please sign in to comment.