]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.5063: error for a command may go over the end of IObuff v8.2.5063
authorBram Moolenaar <Bram@vim.org>
Mon, 6 Jun 2022 14:38:21 +0000 (15:38 +0100)
committerBram Moolenaar <Bram@vim.org>
Mon, 6 Jun 2022 14:38:21 +0000 (15:38 +0100)
Problem:    Error for a command may go over the end of IObuff.
Solution:   Truncate the message.

src/ex_docmd.c
src/testdir/test_cmdline.vim
src/version.c

index cfb40e8d5cfa544c36fab823574220c97a133255..634a1bcef5665a755e3191e66640a916ea508e17 100644 (file)
@@ -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)
index 77965b3f65a3a6414026a99a64b7e9a1351b5d5a..2289c343e9f8259191074857f49b1b20e44079f0 100644 (file)
@@ -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
index 542028606dde51eaee71ebb11785f71f416c0036..dd585c81afe94c11c0488305a1b4a4a1bc88cf36 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    5063,
 /**/
     5062,
 /**/