From: Thierry Fournier Date: Sat, 28 Nov 2020 15:08:02 +0000 (+0100) Subject: BUG/MINOR: lua: Some lua init operation are processed unsafe X-Git-Tag: v2.1.11~42 X-Git-Url: http://git.haproxy.org/?a=commitdiff_plain;h=43d6bb0f44a622189994f2206022b3bdcda9a74a;p=haproxy-2.1.git BUG/MINOR: lua: Some lua init operation are processed unsafe Operation luaL_openlibs() and lua_prepend path are processed whithout the safe context, so in case of failure Haproxy aborts or stops without error message. This patch could be backported until 1.8 (cherry picked from commit 2f05cc6f86ee6beda9c42a6bb99a9a96fad37b68) Signed-off-by: Christopher Faulet (cherry picked from commit 2b7983c78dc9bb0d143280a813ea75ad985b4167) Signed-off-by: Christopher Faulet (cherry picked from commit e1968054851cc40be520493c51be7d2bf50297c5) Signed-off-by: Christopher Faulet --- diff --git a/src/hlua.c b/src/hlua.c index 6ec5409..e247785 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -7773,6 +7773,16 @@ void hlua_init(void) * process of HAProxy, this abort() is tolerated. */ + /* Set safe environment for the initialisation. */ + if (!SET_SAFE_LJMP(gL.T)) { + if (lua_type(gL.T, -1) == LUA_TSTRING) + error_msg = lua_tostring(gL.T, -1); + else + error_msg = "critical error"; + fprintf(stderr, "Lua init: %s.\n", error_msg); + exit(1); + } + /* Initialise lua. */ luaL_openlibs(gL.T); #define HLUA_PREPEND_PATH_TOSTRING1(x) #x @@ -7786,16 +7796,6 @@ void hlua_init(void) #undef HLUA_PREPEND_PATH_TOSTRING #undef HLUA_PREPEND_PATH_TOSTRING1 - /* Set safe environment for the initialisation. */ - if (!SET_SAFE_LJMP(gL.T)) { - if (lua_type(gL.T, -1) == LUA_TSTRING) - error_msg = lua_tostring(gL.T, -1); - else - error_msg = "critical error"; - fprintf(stderr, "Lua init: %s.\n", error_msg); - exit(1); - } - /* * * Create "core" object.