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

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