mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
fix(lua): prevent SIGSEGV when lua error is NULL in libuv_worker
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.
This commit is contained in:
parent
51ccd12b3d
commit
a5b1b83a26
@ -276,10 +276,9 @@ static int nlua_luv_thread_common_cfpcall(lua_State *lstate, int nargs, int nres
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
const char *error = lua_tostring(lstate, -1);
|
const char *error = lua_tostring(lstate, -1);
|
||||||
|
|
||||||
loop_schedule_deferred(&main_loop,
|
loop_schedule_deferred(&main_loop,
|
||||||
event_create(nlua_luv_error_event,
|
event_create(nlua_luv_error_event,
|
||||||
xstrdup(error),
|
error != NULL ? xstrdup(error) : NULL,
|
||||||
(void *)(intptr_t)(is_callback
|
(void *)(intptr_t)(is_callback
|
||||||
? kThreadCallback
|
? kThreadCallback
|
||||||
: kThread)));
|
: kThread)));
|
||||||
|
@ -19,6 +19,26 @@ describe('thread', function()
|
|||||||
screen = Screen.new(50, 10)
|
screen = Screen.new(50, 10)
|
||||||
end)
|
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
|
||||||
|
{3: }|
|
||||||
|
{9:Error in luv thread:} |
|
||||||
|
{9:[NULL]} |
|
||||||
|
{6:Press ENTER or type command to continue}^ |
|
||||||
|
]])
|
||||||
|
feed('<cr>')
|
||||||
|
assert_alive()
|
||||||
|
end)
|
||||||
|
|
||||||
it('entry func is executed in protected mode', function()
|
it('entry func is executed in protected mode', function()
|
||||||
exec_lua [[
|
exec_lua [[
|
||||||
local thread = vim.uv.new_thread(function()
|
local thread = vim.uv.new_thread(function()
|
||||||
|
Loading…
Reference in New Issue
Block a user