]> granicus.if.org Git - vim/commitdiff
patch 8.1.0985: crash with large number in regexp v8.1.0985
authorBram Moolenaar <Bram@vim.org>
Thu, 28 Feb 2019 05:25:00 +0000 (06:25 +0100)
committerBram Moolenaar <Bram@vim.org>
Thu, 28 Feb 2019 05:25:00 +0000 (06:25 +0100)
Problem:    Crash with large number in regexp. (Kuang-che Wu)
Solution:   Check for long becoming negative int. (closes #)

src/regexp.c
src/testdir/test_search.vim
src/version.c

index 5c06ada1b7cf5457e9b7ac20e76d0a72c7fc339d..d7c5770778e39dda7137bb146654efe1124eb093 100644 (file)
@@ -2228,7 +2228,7 @@ regatom(int *flagp)
                                  default:  i = -1; break;
                              }
 
-                             if (i < 0)
+                             if (i < 0 || i > INT_MAX)
                                  EMSG2_RET_NULL(
                                        _("E678: Invalid character after %s%%[dxouU]"),
                                        reg_magic == MAGIC_ALL);
@@ -3293,7 +3293,7 @@ coll_get_char(void)
        case 'u': nr = gethexchrs(4); break;
        case 'U': nr = gethexchrs(8); break;
     }
-    if (nr < 0)
+    if (nr < 0 || nr > INT_MAX)
     {
        /* If getting the number fails be backwards compatible: the character
         * is a backslash. */
index 5cf70d4d8960bb844548b2764fd2243b18f09fd7..d32369d5a23cc82645132332ec14350ae5062147 100644 (file)
@@ -1212,13 +1212,36 @@ func Test_search_Ctrl_L_combining()
   call Incsearch_cleanup()
 endfunc
 
-func Test_large_hex_chars()
+func Test_large_hex_chars1()
   " This used to cause a crash, the character becomes an NFA state.
   try
     /\%Ufffffc23
   catch
     call assert_match('E678:', v:exception)
   endtry
+  try
+    set re=1
+    /\%Ufffffc23
+  catch
+    call assert_match('E678:', v:exception)
+  endtry
+  set re&
+endfunc
+
+func Test_large_hex_chars2()
+  " This used to cause a crash, the character becomes an NFA state.
+  try
+    /[\Ufffffc1f]
+  catch
+    call assert_match('E486:', v:exception)
+  endtry
+  try
+    set re=1
+    /[\Ufffffc1f]
+  catch
+    call assert_match('E486:', v:exception)
+  endtry
+  set re&
 endfunc
 
 func Test_one_error_msg()
index 74850a0b357be8221a726b543764f08fe229dcc7..9b87302cc8c7dabfb966024258bbcbd193346ad8 100644 (file)
@@ -779,6 +779,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    985,
 /**/
     984,
 /**/