From fe1e2eff062605f7e617885011160a678822fd0c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 8 Dec 2024 09:25:43 +0800 Subject: fix(lua): avoid vim._with() double-free with cmdmod (#31505) --- src/nvim/lua/stdlib.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/lua/stdlib.c') diff --git a/src/nvim/lua/stdlib.c b/src/nvim/lua/stdlib.c index e719d99640..5ebff3a809 100644 --- a/src/nvim/lua/stdlib.c +++ b/src/nvim/lua/stdlib.c @@ -619,6 +619,7 @@ static int nlua_with(lua_State *L) int rets = 0; cmdmod_T save_cmdmod = cmdmod; + CLEAR_FIELD(cmdmod); cmdmod.cmod_flags = flags; apply_cmdmod(&cmdmod); -- cgit From 6bf2a6fc5bb395b67c88cb26d332f882a106c7ab Mon Sep 17 00:00:00 2001 From: luukvbaal Date: Tue, 17 Dec 2024 13:12:22 +0100 Subject: refactor(api): always use TRY_WRAP #31600 Problem: Two separate try/end wrappers, that only marginally differ by restoring a few variables. Wrappers that don't restore previous state are dangerous to use in "api-fast" functions. Solution: Remove wrappers that don't restore the previous state. Always use TRY_WRAP. --- src/nvim/lua/stdlib.c | 48 +++++++++++++++++++++--------------------------- 1 file changed, 21 insertions(+), 27 deletions(-) (limited to 'src/nvim/lua/stdlib.c') diff --git a/src/nvim/lua/stdlib.c b/src/nvim/lua/stdlib.c index 5ebff3a809..4de25f4265 100644 --- a/src/nvim/lua/stdlib.c +++ b/src/nvim/lua/stdlib.c @@ -623,38 +623,32 @@ static int nlua_with(lua_State *L) cmdmod.cmod_flags = flags; apply_cmdmod(&cmdmod); - if (buf || win) { - try_start(); - } - - aco_save_T aco; - win_execute_T win_execute_args; Error err = ERROR_INIT; + TRY_WRAP(&err, { + aco_save_T aco; + win_execute_T win_execute_args; - if (win) { - tabpage_T *tabpage = win_find_tabpage(win); - if (!win_execute_before(&win_execute_args, win, tabpage)) { - goto end; + if (win) { + tabpage_T *tabpage = win_find_tabpage(win); + if (!win_execute_before(&win_execute_args, win, tabpage)) { + goto end; + } + } else if (buf) { + aucmd_prepbuf(&aco, buf); } - } else if (buf) { - aucmd_prepbuf(&aco, buf); - } - int s = lua_gettop(L); - lua_pushvalue(L, 2); - status = lua_pcall(L, 0, LUA_MULTRET, 0); - rets = lua_gettop(L) - s; + int s = lua_gettop(L); + lua_pushvalue(L, 2); + status = lua_pcall(L, 0, LUA_MULTRET, 0); + rets = lua_gettop(L) - s; - if (win) { - win_execute_after(&win_execute_args); - } else if (buf) { - aucmd_restbuf(&aco); - } - -end: - if (buf || win) { - try_end(&err); - } + if (win) { + win_execute_after(&win_execute_args); + } else if (buf) { + aucmd_restbuf(&aco); + } + end:; + }); undo_cmdmod(&cmdmod); cmdmod = save_cmdmod; -- cgit From 2a7d0ed6145bf3f8b139c2694563f460f829813a Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 23 Dec 2024 05:43:52 -0800 Subject: refactor: iwyu #31637 Result of `make iwyu` (after some "fixups"). --- src/nvim/lua/stdlib.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/nvim/lua/stdlib.c') diff --git a/src/nvim/lua/stdlib.c b/src/nvim/lua/stdlib.c index 4de25f4265..2fc9367ead 100644 --- a/src/nvim/lua/stdlib.c +++ b/src/nvim/lua/stdlib.c @@ -18,11 +18,13 @@ #include "nvim/api/private/helpers.h" #include "nvim/ascii_defs.h" #include "nvim/autocmd.h" +#include "nvim/autocmd_defs.h" #include "nvim/buffer_defs.h" #include "nvim/eval/typval.h" #include "nvim/eval/typval_defs.h" #include "nvim/eval/vars.h" #include "nvim/eval/window.h" +#include "nvim/ex_cmds_defs.h" #include "nvim/ex_docmd.h" #include "nvim/ex_eval.h" #include "nvim/fold.h" -- cgit