Skip to content

Commit

Permalink
patch 8.2.5126: substitute may overrun destination buffer
Browse files Browse the repository at this point in the history
Problem:    Substitute may overrun destination buffer.
Solution:   Disallow switching buffers in a substitute expression.
  • Loading branch information
brammool committed Jun 18, 2022
1 parent 09f68a5 commit d6211a5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/ex_docmd.c
Expand Up @@ -7138,9 +7138,10 @@ do_exedit(
#endif
)
{
// Can't edit another file when "curbuf_lock" is set. Only ":edit"
// can bring us here, others are stopped earlier.
if (*eap->arg != NUL && curbuf_locked())
// Can't edit another file when "textlock" or "curbuf_lock" is set.
// Only ":edit" or ":script" can bring us here, others are stopped
// earlier.
if (*eap->arg != NUL && text_or_buf_locked())
return;

n = readonlymode;
Expand Down
13 changes: 13 additions & 0 deletions src/testdir/test_substitute.vim
Expand Up @@ -1063,6 +1063,19 @@ func Test_sub_open_cmdline_win()
call delete('Xresult')
endfunc

" This was editing a script file from the expression
func Test_sub_edit_scriptfile()
new
norm o0000000000000000000000000000000000000000000000000000
func EditScript()
silent! scr! Xfile
endfunc
s/\%')/\=EditScript()

delfunc EditScript
bwipe!
endfunc

" Test for the 2-letter and 3-letter :substitute commands
func Test_substitute_short_cmd()
new
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -734,6 +734,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
5126,
/**/
5125,
/**/
Expand Down

0 comments on commit d6211a5

Please sign in to comment.