changeset 17444:f4ce361bb1e5 v8.1.1720

patch 8.1.1720: crash with very long %[] pattern commit https://github.com/vim/vim/commit/2a5b52758bb327b89d22660cc28c157ec29782e5 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jul 20 18:56:06 2019 +0200 patch 8.1.1720: crash with very long %[] pattern Problem: Crash with very long %[] pattern. (Reza Mirzazade farkhani) Solution: Check for reg_toolong. (closes https://github.com/vim/vim/issues/4703)
author Bram Moolenaar <Bram@vim.org>
date Sat, 20 Jul 2019 19:00:06 +0200
parents 613aced7fe57
children c627aa4e52ae
files src/regexp.c src/testdir/test_regexp_utf8.vim src/version.c
diffstat 3 files changed, 17 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/regexp.c
+++ b/src/regexp.c
@@ -2175,7 +2175,11 @@ regatom(int *flagp)
 				  if (ret == NULL)
 				      ret = br;
 				  else
+				  {
 				      regtail(lastnode, br);
+				      if (reg_toolong)
+					  return NULL;
+				  }
 
 				  ungetchr();
 				  one_exactly = TRUE;
@@ -2200,6 +2204,8 @@ regatom(int *flagp)
 				      if (OP(br) == BRANCH)
 				      {
 					  regtail(br, lastbranch);
+					  if (reg_toolong)
+					      return NULL;
 					  br = OPERAND(br);
 				      }
 				      else
--- a/src/testdir/test_regexp_utf8.vim
+++ b/src/testdir/test_regexp_utf8.vim
@@ -206,3 +206,12 @@ func Test_large_class()
   call assert_equal(1, "\u3042" =~# '[\u3000-\u4000]')
   set re=0
 endfunc
+
+func Test_optmatch_toolong()
+  set re=1
+  " Can only handle about 8000 characters.
+  let pat = '\\%[' .. repeat('x', 9000) .. ']'
+  call assert_fails('call match("abc def", "' .. pat .. '")', 'E339:')
+  set re=0
+endfunc
+
--- a/src/version.c
+++ b/src/version.c
@@ -778,6 +778,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1720,
+/**/
     1719,
 /**/
     1718,