]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: lua: register hlua_init() as a pre-check to fix crash without Lua config
authorWilliam Lallemand <wlallemand@haproxy.com>
Thu, 28 May 2026 16:27:04 +0000 (18:27 +0200)
committerWilliam Lallemand <wlallemand@haproxy.com>
Thu, 28 May 2026 16:46:50 +0000 (18:46 +0200)
Commit 1c59c39171529 deferred hlua_init() to be called lazily from the
config keyword handlers (lua-load, lua-load-per-thread,
lua-prepend-path, tune.lua.openlibs), with a call inside
hlua_post_init() as a safety net for the case where no Lua directive
appears in the configuration at all.

The problem is hlua_init() is a function that allocates internal
servers (socket_proxy, socket_tcp, socket_ssl) that must exist before
haproxy initialize the configuration. But hlua_post_init() is done too
far after this initialization, so the safety net does not work
correctly.

This would results in a crash in the deinit() if no lua
configuration was loaded in haproxy.

   Core was generated by `./haproxy -W -f /dev/null'.
   Program terminated with signal SIGSEGV, Segmentation fault.
   #0  0x00005671c72b1047 in _ceb_first (root=0x30, kofs=16, key_type=CEB_KT_U64, key_len=0,
       is_dup_ptr=0x7ffc13197a14) at include/import/cebtree-prv.h:1160
   1160 if (!*root)
   (gdb) bt
   #0  0x00005671c72b1047 in _ceb_first (root=0x30, kofs=16, key_type=CEB_KT_U64, key_len=0,
       is_dup_ptr=0x7ffc13197a14) at include/import/cebtree-prv.h:1160
   #1  _ceb64_first (root=0x30, kofs=16) at src/_ceb_int.c:73
   #2  ceb64_ofs_first (root=0x30, kofs=16) at src/_ceb_int.c:66
   #3  0x00005671c6be5e6e in srv_close_idle_conns (srv=0x5671fd592a80) at src/server.c:7676
   #4  0x00005671c6d3be17 in deinit_proxy (p=0x5671fd5d7780) at src/proxy.c:393
   #5  0x00005671c6d3c536 in proxy_drop (p=0x5671fd5d7780) at src/proxy.c:479
   #6  0x00005671c6aed998 in hlua_deinit () at src/hlua.c:14934
   #7  0x00005671c6db2e41 in deinit () at src/haproxy.c:2846
   #8  0x00005671c6db3d98 in deinit_and_exit (status=0) at src/haproxy.c:2966
   #9  0x00005671c6db6111 in main (argc=4, argv=0x7ffc131983c8) at src/haproxy.c:3997

The fix is to do the initialization earlier, in a pre-check callback.

Thanks to Amaury for reporting this issue.

No backport needed.

src/hlua.c

index 56acdc7893433c287bb0e31da53bfdf1bdeaf771..ca405c9d3b215c5eaa09ab1497601742f4c19ddf 100644 (file)
@@ -14022,10 +14022,6 @@ int hlua_post_init()
 
        hlua_body = 0;
 
-       /* Ensure the Lua VM is initialised even if no Lua directive appeared
-        * in the configuration (e.g. no global section at all).
-        */
-       hlua_init();
 
 #if defined(USE_OPENSSL)
        /* Initialize SSL server. */
@@ -14945,3 +14941,14 @@ static void hlua_register_build_options(void)
 }
 
 INITCALL0(STG_REGISTER, hlua_register_build_options);
+
+/* Ensure the Lua VM is initialised even if no Lua directive appeared
+ * in the configuration (e.g. no global section at all).
+ */
+static int hlua_pre_check(void)
+{
+       hlua_init();
+       return ERR_NONE;
+}
+
+REGISTER_PRE_CHECK(hlua_pre_check);