]> granicus.if.org Git - vim/commitdiff
patch 8.2.4261: accessing invalid memory in a regular expression v8.2.4261
authorBram Moolenaar <Bram@vim.org>
Sun, 30 Jan 2022 16:42:56 +0000 (16:42 +0000)
committerBram Moolenaar <Bram@vim.org>
Sun, 30 Jan 2022 16:42:56 +0000 (16:42 +0000)
Problem:    Accessing invalid memory when a regular expression checks the
            Visual area while matching in a string.
Solution:   Do not try matching the Visual area in a string.

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

index c9e781b4a6c21f7e745cd95dbd2258bd22372ee9..95057655533e04dc12262a364e5263083603e46a 100644 (file)
@@ -1267,8 +1267,8 @@ reg_match_visual(void)
     colnr_T    cols;
     colnr_T    curswant;
 
-    // Check if the buffer is the current buffer.
-    if (rex.reg_buf != curbuf || VIsual.lnum == 0)
+    // Check if the buffer is the current buffer and not using a string.
+    if (rex.reg_buf != curbuf || VIsual.lnum == 0 || rex.reg_maxline == 0)
        return FALSE;
 
     if (VIsual_active)
index 3e358d6bbbf90baff28d31820e4166b61721b56e..b8b9bbc78bd77d93c413678b3171b1b7450940bb 100644 (file)
@@ -1,6 +1,7 @@
 " Tests for :help
 
 source check.vim
+import './vim9.vim' as v9
 
 func Test_help_restore_snapshot()
   help
@@ -168,5 +169,15 @@ func Test_help_long_argument()
   endtry
 endfunc
 
+func Test_help_using_visual_match()
+  let lines =<< trim END
+      call setline(1, ' ')
+      /^
+      exe "normal \<C-V>\<C-V>"
+      h5\%V\80]
+  END
+  call v9.CheckScriptFailure(lines, 'E149:')
+endfunc
+
 
 " vim: shiftwidth=2 sts=2 expandtab
index f696b30336ceadf6948120e867dbb688ab743246..4946c3ee2e177fdb70b698e526893e5527eacb86 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4261,
 /**/
     4260,
 /**/