]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: hlua: add check for lua_newstate
authorfirexinghe <xingheyd@163.com>
Thu, 13 Jul 2023 03:03:34 +0000 (11:03 +0800)
committerWilly Tarreau <w@1wt.eu>
Wed, 19 Jul 2023 08:16:14 +0000 (10:16 +0200)
Calling lual_newstate(Init main lua stack) in the hlua_init_state()
function, the return value of lua_newstate() may be NULL (for example
in case of OOM). In this case, L will be NULL, and then crash happens
in lua_getextraspace(). So, we add a check for lua_newstate.

This should be backported at least to 2.4, maybe further.

src/hlua.c

index d228563e8d94bac25b7a069095c798965eee5d6e..0972964d9db988881864f760281fc77ba0e6ecb5 100644 (file)
@@ -13120,6 +13120,13 @@ lua_State *hlua_init_state(int thread_num)
        /* Init main lua stack. */
        L = lua_newstate(hlua_alloc, &hlua_global_allocator);
 
+       if (!L) {
+               fprintf(stderr,
+                       "Lua init: critical error: lua_newstate() returned NULL."
+                       " This may possibly be caused by a memory allocation error.\n");
+               exit(1);
+       }
+
        /* Initialise Lua context to NULL */
        context = lua_getextraspace(L);
        *context = NULL;