]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: lua: file dedicated to unsafe functions
authorThierry Fournier <tfournier@arpalert.org>
Thu, 21 Jan 2016 08:28:58 +0000 (09:28 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 12 Feb 2016 10:08:53 +0000 (11:08 +0100)
When Lua executes functions from its API, these can throws an error.
These function must be executed in a special environment which catch
these error, otherwise a critical error (like segfault) can raise.

This patch add a c file called "hlua_fcn.c" which collect all the
Lua/c function needing safe environment for its execution.

Makefile
include/proto/hlua_fcn.h [new file with mode: 0644]
src/hlua.c
src/hlua_fcn.c [new file with mode: 0644]

index 8087eb1576a80692817083d385f7562d87088c8b..9acbf2bcc217c1cd26a77c82816dfef3f18729af 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -610,7 +610,7 @@ OPTIONS_LDFLAGS += $(LUA_LD_FLAGS) -l$(LUA_LIB_NAME) -lm
 ifneq ($(USE_DL),)
 OPTIONS_LDFLAGS += -ldl
 endif
-OPTIONS_OBJS    += src/hlua.o
+OPTIONS_OBJS    += src/hlua.o src/hlua_fcn.o
 endif
 
 ifneq ($(USE_DEVICEATLAS),)
diff --git a/include/proto/hlua_fcn.h b/include/proto/hlua_fcn.h
new file mode 100644 (file)
index 0000000..37d07ff
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef _PROTO_HLUA_FCN_H
+#define _PROTO_HLUA_FCN_H
+
+int hlua_fcn_reg_core_fcn(lua_State *L);
+
+#endif /* _PROTO_HLUA_FCN_H */
index 1a31eb267d34b93c32a93d562296b6a9aecfbecf..b4b8980e55c9554f4f551d7ce3463097c7c06c6b 100644 (file)
@@ -24,6 +24,7 @@
 #include <proto/channel.h>
 #include <proto/hdr_idx.h>
 #include <proto/hlua.h>
+#include <proto/hlua_fcn.h>
 #include <proto/map.h>
 #include <proto/obj_type.h>
 #include <proto/pattern.h>
@@ -6632,6 +6633,7 @@ void hlua_init(void)
        hlua_class_function(gL.T, "Warning", hlua_log_warning);
        hlua_class_function(gL.T, "Alert", hlua_log_alert);
        hlua_class_function(gL.T, "done", hlua_done);
+       hlua_fcn_reg_core_fcn(gL.T);
 
        lua_setglobal(gL.T, "core");
 
diff --git a/src/hlua_fcn.c b/src/hlua_fcn.c
new file mode 100644 (file)
index 0000000..6078031
--- /dev/null
@@ -0,0 +1,21 @@
+/* All the functions in this file runs with aLua stack, and can
+ * return with a longjmp. All of these function must be launched
+ * in an environment able to catch a longjmp, otherwise a
+ * critical error can be raised.
+ */
+#include <lauxlib.h>
+#include <lua.h>
+#include <lualib.h>
+
+static void hlua_array_add_fcn(lua_State *L, const char *name,
+                               int (*function)(lua_State *L))
+{
+       lua_pushstring(L, name);
+       lua_pushcclosure(L, function, 0);
+       lua_rawset(L, -3);
+}
+
+int hlua_fcn_reg_core_fcn(lua_State *L)
+{
+       return 0;
+}