diff options
author | William Wong <wnineg@gmail.com> | 2024-08-13 16:25:29 +0800 |
---|---|---|
committer | Lewis Russell <me@lewisr.dev> | 2024-08-14 15:42:55 +0100 |
commit | 6bcefad5a671faab202d5359752b75c6619b9e28 (patch) | |
tree | 41d13f9e4a30998e8ce72a980f345af06d115e1a | |
parent | 9d74dc3ac5a66d0fd34de125476a92ec0a77ca58 (diff) | |
download | rneovim-6bcefad5a671faab202d5359752b75c6619b9e28.tar.gz rneovim-6bcefad5a671faab202d5359752b75c6619b9e28.tar.bz2 rneovim-6bcefad5a671faab202d5359752b75c6619b9e28.zip |
fix(highlight): fix the seg fault caused by the invalid linked hl ids
-rw-r--r-- | src/nvim/api/private/helpers.c | 3 | ||||
-rw-r--r-- | src/nvim/highlight_group.c | 1 |
2 files changed, 3 insertions, 1 deletions
diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 017265e0d3..e00b8c6146 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -774,7 +774,8 @@ int object_to_hl_id(Object obj, const char *what, Error *err) String str = obj.data.string; return str.size ? syn_check_group(str.data, str.size) : 0; } else if (obj.type == kObjectTypeInteger) { - return MAX((int)obj.data.integer, 0); + int id = (int)obj.data.integer; + return (1 <= id && id <= highlight_num_groups()) ? id : 0; } else { api_set_error(err, kErrorTypeValidation, "Invalid highlight: %s", what); return 0; diff --git a/src/nvim/highlight_group.c b/src/nvim/highlight_group.c index d4729474d8..0003aaeb72 100644 --- a/src/nvim/highlight_group.c +++ b/src/nvim/highlight_group.c @@ -1648,6 +1648,7 @@ static bool hlgroup2dict(Dictionary *hl, NS ns_id, int hl_id, Arena *arena) PUT_C(*hl, "default", BOOLEAN_OBJ(true)); } if (link > 0) { + assert(1 <= link && link <= highlight_ga.ga_len); PUT_C(*hl, "link", CSTR_AS_OBJ(hl_table[link - 1].sg_name)); } Dictionary hl_cterm = arena_dict(arena, HLATTRS_DICT_SIZE); |