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

2dd894
diff -up vim80/src/regexp.c.cve4192 vim80/src/regexp.c
2dd894
--- vim80/src/regexp.c.cve4192	2022-01-12 15:21:44.792239040 +0100
2dd894
+++ vim80/src/regexp.c	2022-01-12 15:34:35.190425880 +0100
2dd894
@@ -4203,9 +4203,9 @@ reg_match_visual(void)
2dd894
     if (lnum < top.lnum || lnum > bot.lnum)
2dd894
 	return FALSE;
2dd894
 
2dd894
+    col = (colnr_T)(reginput - regline);
2dd894
     if (mode == 'v')
2dd894
     {
2dd894
-	col = (colnr_T)(reginput - regline);
2dd894
 	if ((lnum == top.lnum && col < top.col)
2dd894
 		|| (lnum == bot.lnum && col >= bot.col + (*p_sel != 'e')))
2dd894
 	    return FALSE;
2dd894
@@ -4220,7 +4220,12 @@ reg_match_visual(void)
2dd894
 	    end = end2;
2dd894
 	if (top.col == MAXCOL || bot.col == MAXCOL)
2dd894
 	    end = MAXCOL;
2dd894
-	cols = win_linetabsize(wp, regline, (colnr_T)(reginput - regline));
2dd894
+
2dd894
+	// getvvcol() flushes rex.line, need to get it again
2dd894
+	regline = reg_getline(reglnum);
2dd894
+	reginput = regline + col;
2dd894
+
2dd894
+	cols = win_linetabsize(wp, regline, col);
2dd894
 	if (cols < start || cols > end - (*p_sel == 'e'))
2dd894
 	    return FALSE;
2dd894
     }
2dd894
diff -up vim80/src/testdir/test_regexp_latin.vim.cve4192 vim80/src/testdir/test_regexp_latin.vim
2dd894
--- vim80/src/testdir/test_regexp_latin.vim.cve4192	2022-01-12 15:21:44.792239040 +0100
2dd894
+++ vim80/src/testdir/test_regexp_latin.vim	2022-01-12 15:36:12.499693099 +0100
2dd894
@@ -80,3 +80,13 @@ func Test_using_invalid_visual_position(
2dd894
   /\%V
2dd894
   bwipe!
2dd894
 endfunc
2dd894
+
2dd894
+func Test_using_visual_position()
2dd894
+  " this was using freed memory
2dd894
+  new
2dd894
+  exe "norm 0o\<Esc>\<C-V>k\<C-X>o0"
2dd894
+  /\%V
2dd894
+  bwipe!
2dd894
+endfunc
2dd894
+
2dd894
+" vim: shiftwidth=2 sts=2 expandtab