From 9e5e586e35c5e16db8a0c2623a5e3b8bea94ca7a Mon Sep 17 00:00:00 2001 From: Tim Duesterhus Date: Mon, 11 Oct 2021 18:51:08 +0200 Subject: [PATCH] BUG/MINOR: lua: Fix lua error handling in `hlua_config_prepend_path()` Set an `lua_atpanic()` handler before calling `hlua_prepend_path()` in `hlua_config_prepend_path()`. This prevents the process from abort()ing when `hlua_prepend_path()` fails for some reason. see GitHub Issue #1409 This is a very minor issue that can't happen in practice. No backport needed. --- src/hlua.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/hlua.c b/src/hlua.c index b03d8bb463..1dbaaa3e05 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -11167,8 +11167,31 @@ static int hlua_config_prepend_path(char **args, int section_type, struct proxy } LIST_APPEND(&prepend_path_list, &p->l); - hlua_prepend_path(hlua_states[0], type, path); - hlua_prepend_path(hlua_states[1], type, path); + /* Handle the global state and the per-thread state for the first + * thread. The remaining threads will be initialized based on + * prepend_path_list. + */ + for (size_t i = 0; i < 2; i++) { + lua_State *L = hlua_states[i]; + const char *error; + + if (setjmp(safe_ljmp_env) != 0) { + lua_atpanic(L, hlua_panic_safe); + if (lua_type(L, -1) == LUA_TSTRING) + error = lua_tostring(L, -1); + else + error = "critical error"; + fprintf(stderr, "lua-prepend-path: %s.\n", error); + exit(1); + } else { + lua_atpanic(L, hlua_panic_ljmp); + } + + hlua_prepend_path(L, type, path); + + lua_atpanic(L, hlua_panic_safe); + } + return 0; err2: -- 2.39.5