]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: lua: Some lua init operation are processed unsafe
authorThierry Fournier <thierry.fournier@ozon.io>
Sat, 28 Nov 2020 15:08:02 +0000 (16:08 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 2 Dec 2020 08:45:18 +0000 (09:45 +0100)
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

src/hlua.c

index e1c316bd64955e95927d0324b3d211d6ee47b47f..43a9745e453dd743d19950605ff3cd62edd6cf3d 100644 (file)
@@ -8221,6 +8221,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
@@ -8234,16 +8244,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.