0
0
mirror of https://github.com/vim/vim.git synced 2025-09-27 04:14:06 -04:00

patch 9.0.1873: [security] heap-buffer-overflow in vim_regsub_both

Problem:  heap-buffer-overflow in vim_regsub_both
Solution: Disallow exchanging windows when textlock is active

Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Christian Brabandt
2023-09-05 20:18:06 +02:00
parent d2a08ba0fa
commit f6d28fe2c9
5 changed files with 19 additions and 0 deletions

View File

@@ -4519,6 +4519,9 @@ ex_substitute(exarg_T *eap)
{ {
nmatch = curbuf->b_ml.ml_line_count - sub_firstlnum + 1; nmatch = curbuf->b_ml.ml_line_count - sub_firstlnum + 1;
skip_match = TRUE; skip_match = TRUE;
// safety check
if (nmatch < 0)
goto skip;
} }
// Need room for: // Need room for:

Binary file not shown.

View File

@@ -46,6 +46,7 @@ func Test_crash1()
let file = 'crash/poc_tagfunc.vim' let file = 'crash/poc_tagfunc.vim'
let args = printf(cmn_args, vim, file) let args = printf(cmn_args, vim, file)
" using || because this poc causes vim to exit with exitstatus != 0
call term_sendkeys(buf, args .. call term_sendkeys(buf, args ..
\ ' || echo "crash 5: [OK]" >> X_crash1_result.txt' .. "\<cr>") \ ' || echo "crash 5: [OK]" >> X_crash1_result.txt' .. "\<cr>")
@@ -59,6 +60,13 @@ func Test_crash1()
call delete('X') call delete('X')
call TermWait(buf, 3000) 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
call term_sendkeys(buf, args ..
\ ' && echo "crash 7: [OK]" >> X_crash1_result.txt' .. "\<cr>")
call TermWait(buf, 1000)
" clean up " clean up
exe buf .. "bw!" exe buf .. "bw!"
@@ -71,6 +79,7 @@ func Test_crash1()
\ 'crash 4: [OK]', \ 'crash 4: [OK]',
\ 'crash 5: [OK]', \ 'crash 5: [OK]',
\ 'crash 6: [OK]', \ 'crash 6: [OK]',
\ 'crash 7: [OK]',
\ ] \ ]
call assert_equal(expected, getline(1, '$')) call assert_equal(expected, getline(1, '$'))

View File

@@ -699,6 +699,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1873,
/**/ /**/
1872, 1872,
/**/ /**/

View File

@@ -1733,6 +1733,11 @@ win_exchange(long Prenum)
beep_flush(); beep_flush();
return; return;
} }
if (text_or_buf_locked())
{
beep_flush();
return;
}
#ifdef FEAT_GUI #ifdef FEAT_GUI
need_mouse_correct = TRUE; need_mouse_correct = TRUE;