]> granicus.if.org Git - vim/commitdiff
patch 8.2.3757: an overlong highlight group name is silently truncated v8.2.3757
authorerw7 <erw7.github@gmail.com>
Tue, 7 Dec 2021 21:29:20 +0000 (21:29 +0000)
committerBram Moolenaar <Bram@vim.org>
Tue, 7 Dec 2021 21:29:20 +0000 (21:29 +0000)
Problem:    An overlong highlight group name is silently truncated.
Solution:   Give an error if the name is too long. (closes #9289)

src/errors.h
src/highlight.c
src/testdir/test_highlight.vim
src/version.c

index a494de3722ceaae444c5d765fef26c881ebdc13c..452ff451b300fe546557ca5c7bc63959dad31324 100644 (file)
@@ -756,3 +756,5 @@ EXTERN char e_line_number_out_of_range[]
        INIT(= N_("E1247: Line number out of range"));
 EXTERN char e_closure_called_from_invalid_context[]
        INIT(= N_("E1248: Closure called from invalid context"));
+EXTERN char e_highlight_group_name_too_long[]
+       INIT(= N_("E1249: Highlight group name too long"));
index 2deda6829cf6f6459b7ddf6f57068ca9678270b7..9502428aa2c4a20fdf29708ba2c9cf840f78ff95 100644 (file)
@@ -18,6 +18,8 @@
 #define SG_GUI         4       // gui has been set
 #define SG_LINK                8       // link has been set
 
+#define MAX_SYN_NAME   200
+
 /*
  * The "term", "cterm" and "gui" arguments can be any combination of the
  * following names, separated by commas (but no spaces!).
@@ -3328,12 +3330,12 @@ set_hl_attr(
 syn_name2id(char_u *name)
 {
     int                i;
-    char_u     name_u[200];
+    char_u     name_u[MAX_SYN_NAME + 1];
 
     // Avoid using stricmp() too much, it's slow on some systems
     // Avoid alloc()/free(), these are slow too.  ID names over 200 chars
     // don't deserve to be found!
-    vim_strncpy(name_u, name, 199);
+    vim_strncpy(name_u, name, MAX_SYN_NAME);
     vim_strup(name_u);
     for (i = highlight_ga.ga_len; --i >= 0; )
        if (HL_TABLE()[i].sg_name_u != NULL
@@ -3411,6 +3413,11 @@ syn_check_group(char_u *pp, int len)
     int            id;
     char_u  *name;
 
+    if (len > MAX_SYN_NAME)
+    {
+       emsg(_(e_highlight_group_name_too_long));
+       return 0;
+    }
     name = vim_strnsave(pp, len);
     if (name == NULL)
        return 0;
index 8e340bc1eacb8c1b9e8284fd75a55ac993980ed8..001cd39dbd8628bcffdec602eec8d8f9a22d5644 100644 (file)
@@ -740,6 +740,7 @@ func Test_highlight_cmd_errors()
     call assert_fails('hi Xcomment ctermbg=fg', 'E419:')
     call assert_fails('hi Xcomment ctermfg=bg', 'E420:')
     call assert_fails('hi Xcomment ctermfg=ul', 'E453:')
+    call assert_fails('hi ' .. repeat('a', 201) .. ' ctermfg=black', 'E1249:')
   endif
 
   " Try using a very long terminal code. Define a dummy terminal code for this
index c586acbd2ff94ca98e48a310f676ff11d4c2dab4..ccd3cf4bb2043cebb818ba3e307c02b283ab3c46 100644 (file)
@@ -753,6 +753,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3757,
 /**/
     3756,
 /**/