aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames McCoy <jamessan@jamessan.com>2021-12-08 21:35:14 -0500
committerJames McCoy <jamessan@jamessan.com>2021-12-08 21:48:00 -0500
commitf3fb77c40262f47e30ebefec547f5c6f83ff58e6 (patch)
treea1e77a6bd4a4f2034e1c2286e741c77a5ba80cd7
parented35e20640ca1d5412550a2df5930b090acee57c (diff)
downloadrneovim-f3fb77c40262f47e30ebefec547f5c6f83ff58e6.tar.gz
rneovim-f3fb77c40262f47e30ebefec547f5c6f83ff58e6.tar.bz2
rneovim-f3fb77c40262f47e30ebefec547f5c6f83ff58e6.zip
vim-patch:8.2.3757: an overlong highlight group name is silently truncated
Problem: An overlong highlight group name is silently truncated. Solution: Give an error if the name is too long. (closes vim/vim#9289) https://github.com/vim/vim/commit/f7f7aaf8aaad34a38d3f159e031c5bcf3394f8f1
-rw-r--r--src/nvim/globals.h2
-rw-r--r--src/nvim/syntax.c11
-rw-r--r--src/nvim/testdir/test_highlight.vim7
3 files changed, 17 insertions, 3 deletions
diff --git a/src/nvim/globals.h b/src/nvim/globals.h
index b2422fd531..938e9c7db7 100644
--- a/src/nvim/globals.h
+++ b/src/nvim/globals.h
@@ -997,6 +997,8 @@ EXTERN char e_non_empty_string_required[] INIT(= N_("E1142: Non-empty string req
EXTERN char e_cannot_define_autocommands_for_all_events[] INIT(= N_("E1155: Cannot define autocommands for ALL events"));
+EXTERN char e_highlight_group_name_too_long[] INIT(= N_("E1249: Highlight group name too long"));
+
EXTERN char top_bot_msg[] INIT(= N_("search hit TOP, continuing at BOTTOM"));
EXTERN char bot_top_msg[] INIT(= N_("search hit BOTTOM, continuing at TOP"));
diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c
index 7eb33d8fdc..9a133eeadf 100644
--- a/src/nvim/syntax.c
+++ b/src/nvim/syntax.c
@@ -115,6 +115,8 @@ static int include_none = 0; // when 1 include "nvim/None"
static int include_default = 0; // when 1 include "nvim/default"
static int include_link = 0; // when 2 include "nvim/link" and "clear"
+#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!).
static char *(hl_name_table[]) =
@@ -7625,10 +7627,9 @@ int syn_name2id(const char *name)
int syn_name2id_len(const char_u *name, size_t len)
FUNC_ATTR_NONNULL_ALL
{
- char name_u[201];
+ char name_u[MAX_SYN_NAME + 1];
- if (len == 0 || len > 200) {
- // ID names over 200 chars don't deserve to be found!
+ if (len == 0 || len > MAX_SYN_NAME) {
return 0;
}
@@ -7686,6 +7687,10 @@ char_u *syn_id2name(int id)
/// @return 0 for failure else the id of the group
int syn_check_group(const char *name, int len)
{
+ if (len > MAX_SYN_NAME) {
+ emsg(_(e_highlight_group_name_too_long));
+ return 0;
+ }
int id = syn_name2id_len((char_u *)name, len);
if (id == 0) { // doesn't exist yet
return syn_add_group(vim_strnsave((char_u *)name, len));
diff --git a/src/nvim/testdir/test_highlight.vim b/src/nvim/testdir/test_highlight.vim
index c38bfa5677..899eb530ec 100644
--- a/src/nvim/testdir/test_highlight.vim
+++ b/src/nvim/testdir/test_highlight.vim
@@ -661,6 +661,13 @@ function Test_no_space_before_xxx()
let &columns = l:org_columns
endfunction
+" Test for :highlight command errors
+func Test_highlight_cmd_errors()
+ if has('gui_running') || has('nvim')
+ call assert_fails('hi ' .. repeat('a', 201) .. ' ctermfg=black', 'E1249:')
+ endif
+endfunc
+
" Test for using RGB color values in a highlight group
func Test_xxlast_highlight_RGB_color()
CheckCanRunGui