Blame SOURCES/0001-patch-8.2.3949-using-freed-memory-with-V.patch

423208
diff -up vim82/src/regexp.c.cve4192 vim82/src/regexp.c
423208
--- vim82/src/regexp.c.cve4192	2021-03-22 10:02:42.000000000 +0100
423208
+++ vim82/src/regexp.c	2022-01-13 10:54:17.629176807 +0100
423208
@@ -1316,9 +1316,9 @@ reg_match_visual(void)
423208
     if (lnum < top.lnum || lnum > bot.lnum)
423208
 	return FALSE;
423208
 
423208
+    col = (colnr_T)(rex.input - rex.line);
423208
     if (mode == 'v')
423208
     {
423208
-	col = (colnr_T)(rex.input - rex.line);
423208
 	if ((lnum == top.lnum && col < top.col)
423208
 		|| (lnum == bot.lnum && col >= bot.col + (*p_sel != 'e')))
423208
 	    return FALSE;
423208
@@ -1333,7 +1333,12 @@ reg_match_visual(void)
423208
 	    end = end2;
423208
 	if (top.col == MAXCOL || bot.col == MAXCOL)
423208
 	    end = MAXCOL;
423208
-	cols = win_linetabsize(wp, rex.line, (colnr_T)(rex.input - rex.line));
423208
+
423208
+	// getvvcol() flushes rex.line, need to get it again
423208
+	rex.line = reg_getline(rex.lnum);
423208
+	rex.input = rex.line + col;
423208
+
423208
+	cols = win_linetabsize(wp, rex.line, col);
423208
 	if (cols < start || cols > end - (*p_sel == 'e'))
423208
 	    return FALSE;
423208
     }
423208
diff -up vim82/src/testdir/test_regexp_latin.vim.cve4192 vim82/src/testdir/test_regexp_latin.vim
423208
--- vim82/src/testdir/test_regexp_latin.vim.cve4192	2022-01-13 10:52:05.508789448 +0100
423208
+++ vim82/src/testdir/test_regexp_latin.vim	2022-01-13 10:52:05.510789454 +0100
423208
@@ -946,4 +946,12 @@ func Test_using_invalid_visual_position(
423208
   bwipe!
423208
 endfunc
423208
 
423208
+func Test_using_visual_position()
423208
+  " this was using freed memory
423208
+  new
423208
+  exe "norm 0o\<Esc>\<C-V>k\<C-X>o0"
423208
+  /\%V
423208
+  bwipe!
423208
+endfunc
423208
+
423208
 " vim: shiftwidth=2 sts=2 expandtab