From 9b13ee041fe500f6bdb82c4e92ed78470f32dd02 Mon Sep 17 00:00:00 2001 From: glepnir Date: Thu, 5 Mar 2026 17:42:35 +0800 Subject: [PATCH] fix(api): nvim_set_hl crashes when url= key is passed Problem: Calling nvim_set_hl() with url= crashes because it tries to free arena-owned string memory. Solution: Remove the bad free and return a validation error instead. (cherry picked from commit d19dc6339de70cb661cf0871cc82fdb7fdcbbde7) --- src/nvim/api/vim.c | 4 ++-- test/functional/api/highlight_spec.lua | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 1bfb314e9f..b51d1b1423 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -186,8 +186,8 @@ void nvim_set_hl(uint64_t channel_id, Integer ns_id, String name, Dict(highlight // Setting URLs directly through highlight attributes is not supported if (HAS_KEY(val, highlight, url)) { - api_free_string(val->url); - val->url = NULL_STRING; + api_set_error(err, kErrorTypeValidation, "Invalid Key: 'url'"); + return; } HlAttrs attrs = dict2hlattrs(val, true, &link_id, err); diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index 3be4d83532..6329089936 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -238,6 +238,10 @@ describe('API: set highlight', function() ) assert_alive() end) + it("'url' is rejected with an error #38162", function() + eq("Invalid Key: 'url'", pcall_err(api.nvim_set_hl, 0, 'Test', { url = 'https://example.com' })) + assert_alive() + end) end) describe('API: get highlight', function()