From 6f10c70b59fa4e56aa479345fb0caeaac7429bfb Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Tue, 20 Aug 2019 22:58:37 +0200 Subject: patch 8.1.1895: using NULL pointer when out of memory Problem: Using NULL pointer when out of memory. Solution: Bail out or skip the code using the pointer. (Zu-Ming Jiang, closes #4805, closes #4843, closes #4939, closes #4844) --- src/highlight.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/highlight.c') diff --git a/src/highlight.c b/src/highlight.c index db65ffca7..f32081d8a 100644 --- a/src/highlight.c +++ b/src/highlight.c @@ -3016,6 +3016,7 @@ syn_check_group(char_u *pp, int len) syn_add_group(char_u *name) { char_u *p; + char_u *name_up; // Check that the name is ASCII letters, digits and underscore. for (p = name; *p != NUL; ++p) @@ -3061,9 +3062,16 @@ syn_add_group(char_u *name) return 0; } + name_up = vim_strsave_up(name); + if (name_up == NULL) + { + vim_free(name); + return 0; + } + vim_memset(&(HL_TABLE()[highlight_ga.ga_len]), 0, sizeof(hl_group_T)); HL_TABLE()[highlight_ga.ga_len].sg_name = name; - HL_TABLE()[highlight_ga.ga_len].sg_name_u = vim_strsave_up(name); + HL_TABLE()[highlight_ga.ga_len].sg_name_u = name_up; #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) HL_TABLE()[highlight_ga.ga_len].sg_gui_bg = INVALCOLOR; HL_TABLE()[highlight_ga.ga_len].sg_gui_fg = INVALCOLOR; -- cgit v1.2.1