]> granicus.if.org Git - vim/commitdiff
patch 9.0.0527: long sign text may overflow buffer v9.0.0527
authorBram Moolenaar <Bram@vim.org>
Wed, 21 Sep 2022 10:21:57 +0000 (11:21 +0100)
committerBram Moolenaar <Bram@vim.org>
Wed, 21 Sep 2022 10:21:57 +0000 (11:21 +0100)
Problem:    Long sign text may overflow buffer.
Solution:   Use a larger buffer.  Prevent for overflow.

src/drawline.c
src/testdir/test_signs.vim
src/version.c

index c4237561786802784171f8bfa2baad9c418226fa..c77f88848cd8fb6305e2bacfab8e575753cf04fe 100644 (file)
@@ -124,7 +124,9 @@ typedef struct {
     int                saved_c_final;
     int                saved_char_attr;
 
-    char_u     extra[21];              // "%ld " and 'fdc' must fit in here
+    char_u     extra[NUMBUFLEN + MB_MAXBYTES];
+                               // "%ld " and 'fdc' must fit in here, as well
+                               // any text sign
 
 #ifdef FEAT_DIFF
     hlf_T      diff_hlf;       // type of diff highlighting
@@ -259,13 +261,13 @@ get_sign_display_info(
                {
                    if (nrcol)
                    {
-                       int n, width = number_width(wp) - 2;
+                       int width = number_width(wp) - 2;
+                       int n;
 
                        for (n = 0; n < width; n++)
                            wlv->extra[n] = ' ';
-                       wlv->extra[n] = 0;
-                       STRCAT(wlv->extra, wlv->p_extra);
-                       STRCAT(wlv->extra, " ");
+                       vim_snprintf((char *)wlv->extra + n,
+                                 sizeof(wlv->extra) - n, "%s ", wlv->p_extra);
                        wlv->p_extra = wlv->extra;
                    }
                    wlv->c_extra = NUL;
index 790d9b43791761af2d03b2078f470e06fb61f62d..3a99a9b8fb6c472f3169c15f0db063dcbf498168 100644 (file)
@@ -196,6 +196,20 @@ func Test_sign()
                          \ bufnr('%'), 'E155:')
 endfunc
 
+func Test_sign_many_bytes()
+  new
+  set signcolumn=number
+  set number
+  call setline(1, 'some text')
+  " composing characters can use many bytes, check for overflow
+  sign define manyBytes text=▶᷄᷅᷆◀᷄᷅᷆᷇
+  sign place 17 line=1 name=manyBytes
+  redraw
+
+  bwipe!
+  sign undefine manyBytes
+endfunc
+
 " Undefining placed sign is not recommended.
 " Quoting :help sign
 "
index 76955bbdccad054595a3d42d735e5b4246e4f145..21ff87dc3b9863d6c805545ca0d9abd5ff0826cc 100644 (file)
@@ -699,6 +699,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    527,
 /**/
     526,
 /**/