summaryrefslogtreecommitdiffstats
path: root/src/highlight.c
diff options
context:
space:
mode:
authorerw7 <erw7.github@gmail.com>2021-12-07 21:29:20 +0000
committerBram Moolenaar <Bram@vim.org>2021-12-07 21:29:20 +0000
commitf7f7aaf8aaad34a38d3f159e031c5bcf3394f8f1 (patch)
treeae3bccdefbc7cf24680259b8e92981f5037d3993 /src/highlight.c
parent4dc24eb5adbcc76838fae1e900936dd230209d96 (diff)
patch 8.2.3757: an overlong highlight group name is silently truncatedv8.2.3757
Problem: An overlong highlight group name is silently truncated. Solution: Give an error if the name is too long. (closes #9289)
Diffstat (limited to 'src/highlight.c')
-rw-r--r--src/highlight.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/highlight.c b/src/highlight.c
index 2deda6829c..9502428aa2 100644
--- a/src/highlight.c
+++ b/src/highlight.c
@@ -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;