From 0a65d821fcc3fe1cab52b4102f2a55b7aa89df03 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 18 Jan 2022 10:05:31 +0800 Subject: vim-patch:8.2.3494: illegal memory access in utf_head_off Problem: Illegal memory access in utf_head_off. Solution: Check cursor position when reselecting the Visual area. (closes vim/vim#8963) https://github.com/vim/vim/commit/b07626d4afa73dd2af0f03c0d59eed25ee159ef9 Including the XTest_beval -> XTest_block from patch 8.2.3096. --- src/nvim/normal.c | 7 ++----- src/nvim/testdir/test_visual.vim | 22 +++++++++++++++++++++- 2 files changed, 23 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 2b5b47c0b3..418ba133bd 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -5963,11 +5963,8 @@ static void nv_visual(cmdarg_T *cap) * was only one -- webb */ if (resel_VIsual_mode != 'v' || resel_VIsual_line_count > 1) { - curwin->w_cursor.lnum += - resel_VIsual_line_count * cap->count0 - 1; - if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) { - curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; - } + curwin->w_cursor.lnum += resel_VIsual_line_count * cap->count0 - 1; + check_cursor(); } VIsual_mode = resel_VIsual_mode; if (VIsual_mode == 'v') { diff --git a/src/nvim/testdir/test_visual.vim b/src/nvim/testdir/test_visual.vim index d58ca92a2f..2e26da4947 100644 --- a/src/nvim/testdir/test_visual.vim +++ b/src/nvim/testdir/test_visual.vim @@ -1120,7 +1120,27 @@ func Test_visual_block_with_virtualedit() " clean up call term_sendkeys(buf, "\") call StopVimInTerminal(buf) - call delete('XTest_beval') + call delete('XTest_block') +endfunc + +func Test_visual_reselect_with_count() + " this was causing an illegal memory access + let lines =<< trim END + + + + : + r + exe "%norm e3\kr\t" + : + + : + END + call writefile(lines, 'XvisualReselect') + source XvisualReselect + + bwipe! + call delete('XvisualReselect') endfunc -- cgit From ec39e1e421101d2573ca5f9003238adfcd45dcd1 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 18 Jan 2022 10:05:31 +0800 Subject: vim-patch:8.2.3611: crash when using CTRL-W f without finding a file name Problem: Crash when using CTRL-W f without finding a file name. Solution: Bail out when the file name length is zero. https://github.com/vim/vim/commit/615ddd5342b50a6878a907062aa471740bd9a847 --- src/nvim/file_search.c | 4 ++++ src/nvim/normal.c | 9 +++++++-- src/nvim/path.c | 4 ++++ src/nvim/testdir/test_visual.vim | 8 ++++++++ 4 files changed, 23 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index b2cd5c510b..df48370ce1 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -1433,6 +1433,10 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first rel_fname = NULL; } + if (len == 0) { + return NULL; + } + if (first == TRUE) { // copy file name into NameBuff, expanding environment variables save_char = ptr[len]; diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 418ba133bd..1f528ce98a 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -4472,8 +4472,13 @@ bool get_visual_text(cmdarg_T *cap, char_u **pp, size_t *lenp) *pp = ml_get_pos(&VIsual); *lenp = (size_t)curwin->w_cursor.col - (size_t)VIsual.col + 1; } - // Correct the length to include the whole last character. - *lenp += (size_t)(utfc_ptr2len(*pp + (*lenp - 1)) - 1); + if (**pp == NUL) { + *lenp = 0; + } + if (*lenp > 0) { + // Correct the length to include all bytes of the last character. + *lenp += (size_t)(utfc_ptr2len(*pp + (*lenp - 1)) - 1); + } } reset_VIsual_and_resel(); return true; diff --git a/src/nvim/path.c b/src/nvim/path.c index 674d67e21a..8b110d0ded 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -1682,6 +1682,10 @@ char_u *find_file_name_in_path(char_u *ptr, size_t len, int options, long count, char_u *file_name; char_u *tofree = NULL; + if (len == 0) { + return NULL; + } + if ((options & FNAME_INCL) && *curbuf->b_p_inex != NUL) { tofree = (char_u *)eval_includeexpr((char *)ptr, len); if (tofree != NULL) { diff --git a/src/nvim/testdir/test_visual.vim b/src/nvim/testdir/test_visual.vim index 2e26da4947..e1e7765e06 100644 --- a/src/nvim/testdir/test_visual.vim +++ b/src/nvim/testdir/test_visual.vim @@ -1123,6 +1123,14 @@ func Test_visual_block_with_virtualedit() call delete('XTest_block') endfunc +func Test_visual_block_ctrl_w_f() + " Emtpy block selected in new buffer should not result in an error. + au! BufNew foo sil norm f + edit foo + + au! BufNew +endfunc + func Test_visual_reselect_with_count() " this was causing an illegal memory access let lines =<< trim END -- cgit From dda1c8edda86a50d802f777e5ba2379f7ccd6ae8 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 18 Jan 2022 10:05:31 +0800 Subject: vim-patch:8.2.3613: :find test fails Problem: :find test fails. Solution: Put length check inside if block. https://github.com/vim/vim/commit/e015d99abb4276f47ce97bad1ad5ff0c658b1c8a --- src/nvim/file_search.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index df48370ce1..b4becb3066 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -1433,11 +1433,11 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first rel_fname = NULL; } - if (len == 0) { - return NULL; - } + if (first == true) { + if (len == 0) { + return NULL; + } - if (first == TRUE) { // copy file name into NameBuff, expanding environment variables save_char = ptr[len]; ptr[len] = NUL; -- cgit