summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-02-08 11:09:22 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-02-08 11:09:22 +0000
commit63c4d493d145b59d000ff7579aa7893c97d1566e (patch)
tree7b99fa1e539f2fc45a62b496b911810852f3532d
parent1f9916144e1de13431d341efa9d67272ee3773ee (diff)
downloadrspamd-63c4d493d145b59d000ff7579aa7893c97d1566e.tar.gz
rspamd-63c4d493d145b59d000ff7579aa7893c97d1566e.zip
Fix bad lua stack leak caused by returning numbers from SA plugin
-rw-r--r--src/lua/lua_config.c42
1 files changed, 25 insertions, 17 deletions
diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c
index 815959898..bd1f5852f 100644
--- a/src/lua/lua_config.c
+++ b/src/lua/lua_config.c
@@ -940,36 +940,44 @@ lua_metric_symbol_callback (struct rspamd_task *task, gpointer ud)
if (nresults >= 1) {
/* Function returned boolean, so maybe we need to insert result? */
- gboolean res;
+ gint res;
GList *opts = NULL;
gint i;
gdouble flag = 1.0;
if (lua_type (cd->L, level + 1) == LUA_TBOOLEAN) {
res = lua_toboolean (L, level + 1);
- if (res) {
- gint first_opt = 2;
+ }
+ else {
+ res = lua_tonumber (L, level + 1);
+ }
- if (lua_type (L, level + 2) == LUA_TNUMBER) {
- flag = lua_tonumber (L, level + 2);
- /* Shift opt index */
- first_opt = 3;
- }
+ if (res) {
+ gint first_opt = 2;
- for (i = lua_gettop (L); i >= level + first_opt; i--) {
- if (lua_type (L, i) == LUA_TSTRING) {
- const char *opt = lua_tostring (L, i);
+ if (lua_type (L, level + 2) == LUA_TNUMBER) {
+ flag = lua_tonumber (L, level + 2);
+ /* Shift opt index */
+ first_opt = 3;
+ }
+ else {
+ flag = res;
+ }
- opts = g_list_prepend (opts,
- rspamd_mempool_strdup (task->task_pool,
- opt));
- }
+ for (i = lua_gettop (L); i >= level + first_opt; i--) {
+ if (lua_type (L, i) == LUA_TSTRING) {
+ const char *opt = lua_tostring (L, i);
+
+ opts = g_list_prepend (opts,
+ rspamd_mempool_strdup (task->task_pool,
+ opt));
}
- rspamd_task_insert_result (task, cd->symbol, flag, opts);
}
- lua_pop (L, nresults);
+ rspamd_task_insert_result (task, cd->symbol, flag, opts);
}
+
+ lua_pop (L, nresults);
}
}