From: Tim Duesterhus Date: Mon, 11 Oct 2021 16:51:08 +0000 (+0200) Subject: BUG/MINOR: lua: Fix lua error handling in `hlua_config_prepend_path()` X-Git-Tag: v2.5-dev10~69 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9e5e586e35c5;p=thirdparty%2Fhaproxy.git 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. --- 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: