Skip to content

Commit c6fdb15

Browse files
committed
patch 9.0.0025: accessing beyond allocated memory with the cmdline window
Problem: Accessing beyond allocated memory when using the cmdline window in Ex mode. Solution: Use "*" instead of "'<,'>" for Visual mode.
1 parent af043e1 commit c6fdb15

3 files changed

Lines changed: 14 additions & 2 deletions

File tree

src/ex_docmd.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3118,9 +3118,11 @@ parse_command_modifiers(
31183118
size_t len = STRLEN(cmd_start);
31193119

31203120
// Special case: empty command uses "+":
3121-
// "'<,'>mods" -> "mods'<,'>+
3121+
// "'<,'>mods" -> "mods *+
3122+
// Use "*" instead of "'<,'>" to avoid the command getting
3123+
// longer, in case is was allocated.
31223124
mch_memmove(orig_cmd, cmd_start, len);
3123-
STRCPY(orig_cmd + len, "'<,'>+");
3125+
STRCPY(orig_cmd + len, " *+");
31243126
}
31253127
else
31263128
{

src/testdir/test_cmdline.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2103,6 +2103,14 @@ func Test_cmdwin_insert_mode_close()
21032103
call assert_equal(1, winnr('$'))
21042104
endfunc
21052105

2106+
func Test_cmdwin_ex_mode_with_modifier()
2107+
" this was accessing memory after allocated text in Ex mode
2108+
new
2109+
call setline(1, ['some', 'text', 'lines'])
2110+
silent! call feedkeys("gQnormal vq:atopleft\<C-V>\<CR>\<CR>", 'xt')
2111+
bwipe!
2112+
endfunc
2113+
21062114
" test that ";" works to find a match at the start of the first line
21072115
func Test_zero_line_search()
21082116
new

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,8 @@ static char *(features[]) =
735735

736736
static int included_patches[] =
737737
{ /* Add new patch number below this line */
738+
/**/
739+
25,
738740
/**/
739741
24,
740742
/**/

0 commit comments

Comments
 (0)