Skip to content

Commit

Permalink
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.
  • Loading branch information
brammool committed May 17, 2022
1 parent bd3a9d2 commit 4748c4b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/scriptfile.c
Expand Up @@ -1965,15 +1965,16 @@ get_one_sourceline(source_cookie_T *sp)
break;
buf = (char_u *)ga.ga_data;
buf[ga.ga_len++] = NUL;
len = ga.ga_len;
}
else
{
buf = (char_u *)ga.ga_data;
if (fgets((char *)buf + ga.ga_len, ga.ga_maxlen - ga.ga_len,
sp->fp) == NULL)
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 src/testdir/test_source.vim
Expand Up @@ -652,6 +652,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
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -746,6 +746,8 @@ static char *(features[]) =

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

0 comments on commit 4748c4b

Please sign in to comment.