From b245bc26da34211a8eedd4a7a4cd8fd3f4349331 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 28 Apr 2015 14:44:21 +0100 Subject: [PATCH] Do not try to dereference null pointer. --- src/plugins/regexp.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/plugins/regexp.c b/src/plugins/regexp.c index 2bf88ac930..30824949d3 100644 --- a/src/plugins/regexp.c +++ b/src/plugins/regexp.c @@ -185,7 +185,7 @@ static gboolean rspamd_lua_call_expression_func( lua_State *L = lua_data->L; struct rspamd_task **ptask; struct expression_argument *arg; - gint pop = 0, i; + gint pop = 0, i, nargs = 0; lua_rawgeti (L, LUA_REGISTRYINDEX, lua_data->idx); /* Now we got function in top of stack */ @@ -194,24 +194,27 @@ static gboolean rspamd_lua_call_expression_func( *ptask = task; /* Now push all arguments */ - for (i = 0; i < (gint)args->len; i ++) { - arg = &g_array_index (args, struct expression_argument, i); - if (arg) { - switch (arg->type) { - case EXPRESSION_ARGUMENT_NORMAL: - lua_pushstring (L, (const gchar *) arg->data); - break; - case EXPRESSION_ARGUMENT_BOOL: - lua_pushboolean (L, (gboolean) GPOINTER_TO_SIZE(arg->data)); - break; - default: - msg_err("cannot pass custom params to lua function"); - return FALSE; + if (args) { + for (i = 0; i < (gint)args->len; i ++) { + arg = &g_array_index (args, struct expression_argument, i); + if (arg) { + switch (arg->type) { + case EXPRESSION_ARGUMENT_NORMAL: + lua_pushstring (L, (const gchar *) arg->data); + break; + case EXPRESSION_ARGUMENT_BOOL: + lua_pushboolean (L, (gboolean) GPOINTER_TO_SIZE(arg->data)); + break; + default: + msg_err("cannot pass custom params to lua function"); + return FALSE; + } } } + nargs = args->len; } - if (lua_pcall (L, args->len, 1, 0) != 0) { + if (lua_pcall (L, nargs + 1, 1, 0) != 0) { msg_info("call to lua function failed: %s", lua_tostring (L, -1)); return FALSE; } -- 2.47.3