commit 9c571fc: [Minor] Fix modules loading logic

Vsevolod Stakhov vsevolod at highsecure.ru
Thu Oct 10 16:49:07 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-10-10 17:44:06 +0100
URL: https://github.com/rspamd/rspamd/commit/9c571fcf673e2cd2247b921769059c2399696234 (HEAD -> master)

[Minor] Fix modules loading logic

---
 src/lua/lua_common.c | 35 +++++++++++++++++++++++------------
 1 file changed, 23 insertions(+), 12 deletions(-)

diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c
index d68e8e952..a6766f93f 100644
--- a/src/lua/lua_common.c
+++ b/src/lua/lua_common.c
@@ -1053,12 +1053,24 @@ rspamd_plugins_table_push_elt (lua_State *L, const gchar *field_name,
 		const gchar *new_elt)
 {
 	lua_getglobal (L, rspamd_modules_state_global);
-	lua_pushstring (L, field_name);
-	lua_gettable (L, -2);
-	lua_pushstring (L, new_elt);
-	lua_newtable (L);
-	lua_settable (L, -3);
-	lua_pop (L, 2); /* Global + element */
+
+	if (lua_istable (L, -1)) {
+		lua_pushstring (L, field_name);
+		lua_gettable (L, -2);
+
+		if (lua_istable (L, -1)) {
+			lua_pushstring (L, new_elt);
+			lua_newtable (L);
+			lua_settable (L, -3);
+			lua_pop (L, 2); /* Global + element */
+		}
+		else {
+			lua_pop (L, 2); /* Global + element */
+		}
+	}
+	else {
+		lua_pop (L, 1);
+	}
 }
 
 gboolean
@@ -1070,6 +1082,11 @@ rspamd_init_lua_filters (struct rspamd_config *cfg, gboolean force_load)
 	lua_State *L = cfg->lua_state;
 	gint err_idx;
 
+	pcfg = lua_newuserdata (L, sizeof (struct rspamd_config *));
+	rspamd_lua_setclass (L, "rspamd{config}", -1);
+	*pcfg = cfg;
+	lua_setglobal (L, "rspamd_config");
+
 	cur = g_list_first (cfg->script_modules);
 
 	while (cur) {
@@ -1132,12 +1149,6 @@ rspamd_init_lua_filters (struct rspamd_config *cfg, gboolean force_load)
 			munmap (data, fsize);
 			g_free (lua_fname);
 
-			/* Initialize config structure */
-			pcfg = lua_newuserdata (L, sizeof (struct rspamd_config *));
-			rspamd_lua_setclass (L, "rspamd{config}", -1);
-			*pcfg = cfg;
-			lua_setglobal (L, "rspamd_config");
-
 			if (lua_pcall (L, 0, 0, err_idx) != 0) {
 				msg_err_config ("init of %s failed: %s",
 						module->path,


More information about the Commits mailing list