]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: lua: Fix lua error handling in `hlua_config_prepend_path()`
authorTim Duesterhus <tim@bastelstu.be>
Mon, 11 Oct 2021 16:51:08 +0000 (18:51 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 12 Oct 2021 09:28:57 +0000 (11:28 +0200)
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

index b03d8bb4634f8b936c439ec55509834036b0343a..1dbaaa3e05364dd0d49487b2f4f5366246e099af 100644 (file)
@@ -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: