mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 9.0.1848: [security] buffer-overflow in vim_regsub_both()
Problem: buffer-overflow in vim_regsub_both() Solution: Check remaining space Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
parent
889f6af371
commit
ced2c7394a
@ -4651,6 +4651,9 @@ ex_substitute(exarg_T *eap)
|
|||||||
mch_memmove(new_end, sub_firstline + copycol, (size_t)copy_len);
|
mch_memmove(new_end, sub_firstline + copycol, (size_t)copy_len);
|
||||||
new_end += copy_len;
|
new_end += copy_len;
|
||||||
|
|
||||||
|
if (new_start_len - copy_len < sublen)
|
||||||
|
sublen = new_start_len - copy_len - 1;
|
||||||
|
|
||||||
#ifdef FEAT_EVAL
|
#ifdef FEAT_EVAL
|
||||||
++textlock;
|
++textlock;
|
||||||
#endif
|
#endif
|
||||||
|
@ -2051,7 +2051,8 @@ vim_regsub_both(
|
|||||||
// "flags & REGSUB_COPY" != 0.
|
// "flags & REGSUB_COPY" != 0.
|
||||||
if (copy)
|
if (copy)
|
||||||
{
|
{
|
||||||
if (eval_result[nested] != NULL)
|
if (eval_result[nested] != NULL &&
|
||||||
|
STRLEN(eval_result[nested]) < destlen)
|
||||||
{
|
{
|
||||||
STRCPY(dest, eval_result[nested]);
|
STRCPY(dest, eval_result[nested]);
|
||||||
dst += STRLEN(eval_result[nested]);
|
dst += STRLEN(eval_result[nested]);
|
||||||
|
10
src/testdir/crash/vim_regsub_both
Normal file
10
src/testdir/crash/vim_regsub_both
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
fu R()
|
||||||
|
sil!norm0z=
|
||||||
|
endf
|
||||||
|
cal R()
|
||||||
|
s/\%')/\=R()
|
||||||
|
d
|
||||||
|
no0 normyynore sm:vs0@vvvvvvvvvvse()dir(¼Xtest=csd{so88
|
||||||
|
vs
|
||||||
|
0scr
|
||||||
|
so
|
@ -6,7 +6,7 @@ CheckScreendump
|
|||||||
|
|
||||||
func Test_crash1()
|
func Test_crash1()
|
||||||
" The following used to crash Vim
|
" The following used to crash Vim
|
||||||
let opts = #{wait_for_ruler: 0}
|
let opts = #{wait_for_ruler: 0, rows: 20}
|
||||||
let args = ' -u NONE -i NONE -n -e -s -S '
|
let args = ' -u NONE -i NONE -n -e -s -S '
|
||||||
let buf = RunVimInTerminal(args .. ' crash/poc_huaf1', opts)
|
let buf = RunVimInTerminal(args .. ' crash/poc_huaf1', opts)
|
||||||
call VerifyScreenDump(buf, 'Test_crash_01', {})
|
call VerifyScreenDump(buf, 'Test_crash_01', {})
|
||||||
@ -22,4 +22,13 @@ func Test_crash1()
|
|||||||
|
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_crash2()
|
||||||
|
" The following used to crash Vim
|
||||||
|
let opts = #{wait_for_ruler: 0, rows: 20}
|
||||||
|
let args = ' -u NONE -i NONE -n -e -s -S '
|
||||||
|
let buf = RunVimInTerminal(args .. ' crash/vim_regsub_both', opts)
|
||||||
|
call VerifyScreenDump(buf, 'Test_crash_01', {})
|
||||||
|
exe buf .. "bw!"
|
||||||
|
endfunc
|
||||||
|
|
||||||
" vim: shiftwidth=2 sts=2 expandtab
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
@ -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 */
|
||||||
|
/**/
|
||||||
|
1848,
|
||||||
/**/
|
/**/
|
||||||
1847,
|
1847,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user