# HG changeset patch # User Bram Moolenaar # Date 1648580404 -7200 # Node ID 5bf82b918cb25ed6e95beb12ed1a9195afe0cefe # Parent 56e2b05a232f2f06101cbdfd7e43648056623323 patch 8.2.4647: "source" can read past end of copied line Commit: https://github.com/vim/vim/commit/2bdad6126778f907c0b98002bfebf0e611a3f5db Author: Bram Moolenaar Date: Tue Mar 29 19:52:12 2022 +0100 patch 8.2.4647: "source" can read past end of copied line Problem: "source" can read past end of copied line. Solution: Add a terminating NUL. diff --git a/src/scriptfile.c b/src/scriptfile.c --- a/src/scriptfile.c +++ b/src/scriptfile.c @@ -1918,7 +1918,10 @@ get_one_sourceline(source_cookie_T *sp) break; // all the lines are processed ga_concat(&ga, ((char_u **)sp->buflines.ga_data)[sp->buf_lnum]); sp->buf_lnum++; + if (ga_grow(&ga, 1) == FAIL) + break; buf = (char_u *)ga.ga_data; + buf[ga.ga_len++] = NUL; } else { diff --git a/src/testdir/test_source.vim b/src/testdir/test_source.vim --- a/src/testdir/test_source.vim +++ b/src/testdir/test_source.vim @@ -646,4 +646,13 @@ func Test_source_buffer_vim9() %bw! endfunc +func Test_source_buffer_long_line() + " This was reading past the end of the line. + new + norm300gr0 + so + bwipe! +endfunc + + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -751,6 +751,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 4647, +/**/ 4646, /**/ 4645,