fix(lua): prevent SIGSEGV when lua error is NULL in libuv_worker (#32091)

Problem:
Calling `xstrdup` with a NULL pointer causes a SIGSEGV if `lua_tostring` returns
NULL in `nlua_luv_thread_common_cfpcall`.

Crash stack trace:
- `_platform_strlen` → `xstrdup` (memory.c:469)
- `nlua_luv_thread_common_cfpcall` (executor.c:281)

Solution:
Check if `lua_tostring` returns NULL and pass NULL to `event_create` to avoid the crash.

(cherry picked from commit a5b1b83a26)

Co-authored-by: 林玮 (Jade Lin) <linw1995@icloud.com>
This commit is contained in:
neovim-backports[bot]
2025-01-19 01:00:18 +00:00
committed by GitHub
parent baaaf6a9e7
commit 4b25fe09cc
2 changed files with 21 additions and 2 deletions

View File

@@ -27,6 +27,26 @@ describe('thread', function()
})
end)
it('handle non-string error', function()
exec_lua [[
local thread = vim.uv.new_thread(function()
error()
end)
vim.uv.thread_join(thread)
]]
screen:expect([[
|
{1:~ }|*5
{2: }|
{3:Error in luv thread:} |
{3:[NULL]} |
{4:Press ENTER or type command to continue}^ |
]])
feed('<cr>')
assert_alive()
end)
it('entry func is executed in protected mode', function()
exec_lua [[
local thread = vim.uv.new_thread(function()