From: Vsevolod Stakhov Date: Tue, 28 Apr 2015 13:44:21 +0000 (+0100) Subject: Do not try to dereference null pointer. X-Git-Tag: 0.9.0~135 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b245bc26da34211a8eedd4a7a4cd8fd3f4349331;p=thirdparty%2Frspamd.git Do not try to dereference null pointer. --- 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; }