Mercurial > vim
changeset 9923:935e13935848 v7.4.2235
commit https://github.com/vim/vim/commit/989f592f7ffcbafdc4ec35cee4dc65bd053e2077
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Aug 21 15:26:54 2016 +0200
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)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 21 Aug 2016 15:30:07 +0200 |
parents | 14634d142f05 |
children | cb0cb5358209 |
files | src/evalfunc.c src/testdir/test_expr.vim src/version.c |
diffstat | 3 files changed, 12 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -11491,7 +11491,11 @@ f_submatch(typval_T *argvars, typval_T * no = (int)get_tv_number_chk(&argvars[0], &error); if (error) return; - error = FALSE; + if (no < 0 || no >= NSUBEXP) + { + EMSGN(_("E935: invalid submatch number: %d"), no); + return; + } if (argvars[1].v_type != VAR_UNKNOWN) retList = (int)get_tv_number_chk(&argvars[1], &error); if (error)
--- a/src/testdir/test_expr.vim +++ b/src/testdir/test_expr.vim @@ -198,6 +198,11 @@ func Test_substitute_expr() call assert_equal('--', substitute('xxx', 'x*', {-> '-' . Recurse() . '-'}, '')) 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() call assert_equal('123456789-123456789=', substitute('123456789', \ '\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)',