forked from aniani/vim
patch 7.4.2235
Problem: submatch() does not check for a valid argument. Solution: Give an error if the argument is out of range. (Dominique Pelle)
This commit is contained in:
@@ -11491,7 +11491,11 @@ f_submatch(typval_T *argvars, typval_T *rettv)
|
|||||||
no = (int)get_tv_number_chk(&argvars[0], &error);
|
no = (int)get_tv_number_chk(&argvars[0], &error);
|
||||||
if (error)
|
if (error)
|
||||||
return;
|
return;
|
||||||
error = FALSE;
|
if (no < 0 || no >= NSUBEXP)
|
||||||
|
{
|
||||||
|
EMSGN(_("E935: invalid submatch number: %d"), no);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (argvars[1].v_type != VAR_UNKNOWN)
|
if (argvars[1].v_type != VAR_UNKNOWN)
|
||||||
retList = (int)get_tv_number_chk(&argvars[1], &error);
|
retList = (int)get_tv_number_chk(&argvars[1], &error);
|
||||||
if (error)
|
if (error)
|
||||||
|
@@ -198,6 +198,11 @@ func Test_substitute_expr()
|
|||||||
call assert_equal('--', substitute('xxx', 'x*', {-> '-' . Recurse() . '-'}, ''))
|
call assert_equal('--', substitute('xxx', 'x*', {-> '-' . Recurse() . '-'}, ''))
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_invalid_submatch()
|
||||||
|
" This was causing invalid memory access in Vim-7.4.2232 and older
|
||||||
|
call assert_fails("call substitute('x', '.', {-> submatch(10)}, '')", 'E935:')
|
||||||
|
endfunc
|
||||||
|
|
||||||
func Test_substitute_expr_arg()
|
func Test_substitute_expr_arg()
|
||||||
call assert_equal('123456789-123456789=', substitute('123456789',
|
call assert_equal('123456789-123456789=', substitute('123456789',
|
||||||
\ '\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)',
|
\ '\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)',
|
||||||
|
@@ -763,6 +763,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 */
|
||||||
|
/**/
|
||||||
|
2235,
|
||||||
/**/
|
/**/
|
||||||
2234,
|
2234,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user