]> granicus.if.org Git - vim/commitdiff
patch 8.2.4647: "source" can read past end of copied line v8.2.4647
authorBram Moolenaar <Bram@vim.org>
Tue, 29 Mar 2022 18:52:12 +0000 (19:52 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 29 Mar 2022 18:52:12 +0000 (19:52 +0100)
Problem:    "source" can read past end of copied line.
Solution:   Add a terminating NUL.

src/scriptfile.c
src/testdir/test_source.vim
src/version.c

index a334b2f9fc5309aff20e8f4ed2d3b531fed52906..39936a42650a4f5e21fdec8332a2aca13e8aff58 100644 (file)
@@ -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
        {
index 35d14537476dc712df6bd94e2d46f3660206cc70..5f45ab413c8d73290cce9c86a9cde9dc28a971f4 100644 (file)
@@ -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
index 14fd1c369c95ee048382e09e4ab66d7872516fbd..b18de4c5e50243fe8d72b5c4cbb78c61fbf4aa27 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4647,
 /**/
     4646,
 /**/