Skip to content

Commit

Permalink
vim-patch:8.2.4974: ":so" command may read after end of buffer
Browse files Browse the repository at this point in the history
Problem:    ":so" command may read after end of buffer.
Solution:   Compute length of text properly.

vim/vim@4748c4b

Co-authored-by: Bram Moolenaar <[email protected]>
  • Loading branch information
zeertzjq and brammool committed Apr 24, 2024
1 parent 499c4d8 commit 6918eb3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/nvim/runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -2627,6 +2627,7 @@ static char *get_one_sourceline(source_cookie_T *sp)
ga_grow(&ga, 1);
buf = (char *)ga.ga_data;
buf[ga.ga_len++] = NUL;
len = ga.ga_len;
} else {
buf = ga.ga_data;
retry:
Expand All @@ -2637,8 +2638,8 @@ static char *get_one_sourceline(source_cookie_T *sp)
}
break;
}
len = ga.ga_len + (int)strlen(buf + ga.ga_len);
}
len = ga.ga_len + (int)strlen(buf + ga.ga_len);
#ifdef USE_CRNL
// Ignore a trailing CTRL-Z, when in Dos mode. Only recognize the
// CTRL-Z by its own, or after a NL.
Expand Down
11 changes: 11 additions & 0 deletions test/old/testdir/test_source.vim
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,17 @@ func Test_source_buffer_long_line()
norm300gr0
so
bwipe!

let lines =<< trim END
new
norm 10a0000000000ø00000000000
norm i0000000000000000000
silent! so
END
call writefile(lines, 'Xtest.vim')
source Xtest.vim
bwipe!
call delete('Xtest.vim')
endfunc


Expand Down

0 comments on commit 6918eb3

Please sign in to comment.