Patch 8.2.3757

7 views
Skip to first unread message

Bram Moolenaar

unread,
Dec 7, 2021, 4:29:57 PM12/7/21
to vim...@googlegroups.com

Patch 8.2.3757
Problem: An overlong highlight group name is silently truncated.
Solution: Give an error if the name is too long. (closes #9289)
Files: src/errors.h, src/highlight.c, src/testdir/test_highlight.vim


*** ../vim-8.2.3756/src/errors.h 2021-12-05 22:19:22.832153464 +0000
--- src/errors.h 2021-12-07 21:24:34.347223610 +0000
***************
*** 756,758 ****
--- 756,760 ----
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"));
*** ../vim-8.2.3756/src/highlight.c 2021-11-24 20:28:23.599595260 +0000
--- src/highlight.c 2021-12-07 21:25:11.867104915 +0000
***************
*** 18,23 ****
--- 18,25 ----
#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,3339 ****
syn_name2id(char_u *name)
{
int i;
! char_u name_u[200];

// 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_strup(name_u);
for (i = highlight_ga.ga_len; --i >= 0; )
if (HL_TABLE()[i].sg_name_u != NULL
--- 3330,3341 ----
syn_name2id(char_u *name)
{
int i;
! 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, MAX_SYN_NAME);
vim_strup(name_u);
for (i = highlight_ga.ga_len; --i >= 0; )
if (HL_TABLE()[i].sg_name_u != NULL
***************
*** 3411,3416 ****
--- 3413,3423 ----
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;
*** ../vim-8.2.3756/src/testdir/test_highlight.vim 2021-11-24 20:28:23.599595260 +0000
--- src/testdir/test_highlight.vim 2021-12-07 21:24:09.179306127 +0000
***************
*** 740,745 ****
--- 740,746 ----
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
*** ../vim-8.2.3756/src/version.c 2021-12-07 12:23:53.991565068 +0000
--- src/version.c 2021-12-07 21:27:19.094736412 +0000
***************
*** 755,756 ****
--- 755,758 ----
{ /* Add new patch number below this line */
+ /**/
+ 3757,
/**/

--
A)bort, R)etry, D)o it right this time

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages