changeset 27466:8ed815f061af v8.2.4261

patch 8.2.4261: accessing invalid memory in a regular expression Commit: https://github.com/vim/vim/commit/679d66c2d21dfe03d0f89b9a818b0aaebb4c3b87 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jan 30 16:42:56 2022 +0000 patch 8.2.4261: accessing invalid memory in a regular expression 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.
author Bram Moolenaar <Bram@vim.org>
date Sun, 30 Jan 2022 17:45:03 +0100
parents 976fb709e91d
children 853e9023ca7f
files src/regexp.c src/testdir/test_help.vim src/version.c
diffstat 3 files changed, 15 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/regexp.c
+++ b/src/regexp.c
@@ -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)
--- a/src/testdir/test_help.vim
+++ b/src/testdir/test_help.vim
@@ -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€]
+  END
+  call v9.CheckScriptFailure(lines, 'E149:')
+endfunc
+
 
 " vim: shiftwidth=2 sts=2 expandtab
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    4261,
+/**/
     4260,
 /**/
     4259,