From: Markus Koschany Date: Sun, 23 Oct 2022 17:11:51 +0200 Subject: CVE-2022-0319 Origin: https://github.com/vim/vim/commit/05b27615481e72e3b338bb12990fb3e0c2ecc2a9 --- src/testdir/test_visual.vim | 10 ++++++++++ src/window.c | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/src/testdir/test_visual.vim b/src/testdir/test_visual.vim index afeb4da..0841952 100644 --- a/src/testdir/test_visual.vim +++ b/src/testdir/test_visual.vim @@ -3,6 +3,16 @@ if !has('visual') finish endif +" this was causing an ml_get error +func Test_visual_exchange_windows() + enew! + new + call setline(1, ['foo', 'bar']) + exe "normal G\gg\\OO\" + bwipe! + bwipe! +endfunc + func Test_block_shift_multibyte() " Uses double-wide character. diff --git a/src/window.c b/src/window.c index f78fcca..7c7f580 100644 --- a/src/window.c +++ b/src/window.c @@ -1576,6 +1576,11 @@ win_exchange(long Prenum) (void)win_comp_pos(); /* recompute window positions */ + if (wp->w_buffer != curbuf) + reset_VIsual_and_resel(); + else if (VIsual_active) + wp->w_cursor = curwin->w_cursor; + win_enter(wp, TRUE); redraw_all_later(NOT_VALID); }