Skip to content

Commit 989f592

Browse files
committed
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)
1 parent dd12481 commit 989f592

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

src/evalfunc.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11491,7 +11491,11 @@ f_submatch(typval_T *argvars, typval_T *rettv)
1149111491
no = (int)get_tv_number_chk(&argvars[0], &error);
1149211492
if (error)
1149311493
return;
11494-
error = FALSE;
11494+
if (no < 0 || no >= NSUBEXP)
11495+
{
11496+
EMSGN(_("E935: invalid submatch number: %d"), no);
11497+
return;
11498+
}
1149511499
if (argvars[1].v_type != VAR_UNKNOWN)
1149611500
retList = (int)get_tv_number_chk(&argvars[1], &error);
1149711501
if (error)

src/testdir/test_expr.vim

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,11 @@ func Test_substitute_expr()
198198
call assert_equal('--', substitute('xxx', 'x*', {-> '-' . Recurse() . '-'}, ''))
199199
endfunc
200200

201+
func Test_invalid_submatch()
202+
" This was causing invalid memory access in Vim-7.4.2232 and older
203+
call assert_fails("call substitute('x', '.', {-> submatch(10)}, '')", 'E935:')
204+
endfunc
205+
201206
func Test_substitute_expr_arg()
202207
call assert_equal('123456789-123456789=', substitute('123456789',
203208
\ '\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)',

src/version.c

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

764764
static int included_patches[] =
765765
{ /* Add new patch number below this line */
766+
/**/
767+
2235,
766768
/**/
767769
2234,
768770
/**/

0 commit comments

Comments
 (0)