changeset 28903:6a7d94628b5a v8.2.4974

patch 8.2.4974: ":so" command may read after end of buffer Commit: https://github.com/vim/vim/commit/4748c4bd64610cf943a431d215bb1aad51f8d0b4 Author: Bram Moolenaar <Bram@vim.org> Date: Tue May 17 17:47:07 2022 +0100 patch 8.2.4974: ":so" command may read after end of buffer Problem: ":so" command may read after end of buffer. Solution: Compute length of text properly.
author Bram Moolenaar <Bram@vim.org>
date Tue, 17 May 2022 19:00:03 +0200
parents 26d0d6f9b368
children 02398ff5b522
files src/scriptfile.c src/testdir/test_source.vim src/version.c
diffstat 3 files changed, 15 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/scriptfile.c
+++ b/src/scriptfile.c
@@ -1965,6 +1965,7 @@ get_one_sourceline(source_cookie_T *sp)
 		break;
 	    buf = (char_u *)ga.ga_data;
 	    buf[ga.ga_len++] = NUL;
+	    len = ga.ga_len;
 	}
 	else
 	{
@@ -1972,8 +1973,8 @@ get_one_sourceline(source_cookie_T *sp)
 	    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.
--- a/src/testdir/test_source.vim
+++ b/src/testdir/test_source.vim
@@ -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
 
 
--- a/src/version.c
+++ b/src/version.c
@@ -747,6 +747,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    4974,
+/**/
     4973,
 /**/
     4972,