changeset 29083:3de91964bbd6 v8.2.5063

patch 8.2.5063: error for a command may go over the end of IObuff Commit: https://github.com/vim/vim/commit/44a3f3353e0407e9fffee138125a6927d1c9e7e5 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Jun 6 15:38:21 2022 +0100 patch 8.2.5063: error for a command may go over the end of IObuff Problem: Error for a command may go over the end of IObuff. Solution: Truncate the message.
author Bram Moolenaar <Bram@vim.org>
date Mon, 06 Jun 2022 16:45:03 +0200
parents c009a9830f56
children e97abb3ba4e2
files src/ex_docmd.c src/testdir/test_cmdline.vim src/version.c
diffstat 3 files changed, 18 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -3441,9 +3441,17 @@ theend:
     static void
 append_command(char_u *cmd)
 {
-    char_u *s = cmd;
-    char_u *d;
-
+    size_t  len = STRLEN(IObuff);
+    char_u  *s = cmd;
+    char_u  *d;
+
+    if (len > IOSIZE - 100)
+    {
+	// Not enough space, truncate and put in "...".
+	d = IObuff + IOSIZE - 100;
+	d -= mb_head_off(IObuff, d);
+	STRCPY(d, "...");
+    }
     STRCAT(IObuff, ": ");
     d = IObuff + STRLEN(IObuff);
     while (*s != NUL && d - IObuff + 5 < IOSIZE)
--- a/src/testdir/test_cmdline.vim
+++ b/src/testdir/test_cmdline.vim
@@ -3413,4 +3413,9 @@ func Test_recursive_register()
   call assert_equal('yes', caught)
 endfunc
 
+func Test_long_error_message()
+  " the error should be truncated, not overrun IObuff
+  silent! norm Q00000000000000     000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000                                                                                                                                                                                                                        
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
--- a/src/version.c
+++ b/src/version.c
@@ -735,6 +735,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    5063,
+/**/
     5062,
 /**/
     5061,