From 813f1f407f639c1f025298abae9fd0295a30d24c Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 3 Jun 2013 16:24:15 +0100 Subject: [PATCH] Fix some warnings that actually are dangerous. --- src/dkim.c | 2 +- src/lua_worker.c | 14 ++++++++++++++ src/plugins/regexp.c | 19 +++++++++---------- src/protocol.c | 8 ++++---- src/smtp_proxy.c | 4 +++- 5 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/dkim.c b/src/dkim.c index 157b13aee..5e62ab55d 100644 --- a/src/dkim.c +++ b/src/dkim.c @@ -367,7 +367,7 @@ rspamd_dkim_parse_bodylength (rspamd_dkim_context_t* ctx, const gchar *param, gs rspamd_dkim_context_t* rspamd_create_dkim_context (const gchar *sig, memory_pool_t *pool, guint time_jitter, GError **err) { - const gchar *p, *c, *tag, *end; + const gchar *p, *c, *tag = NULL, *end; gsize taglen; gint param = DKIM_PARAM_UNKNOWN; time_t now; diff --git a/src/lua_worker.c b/src/lua_worker.c index c4276968a..723c48707 100644 --- a/src/lua_worker.c +++ b/src/lua_worker.c @@ -381,6 +381,20 @@ lua_accept_socket (gint fd, short what, void *arg) sizeof (struct in_addr)); addr_str = g_strdup (inet_ntoa (su.s4.sin_addr)); } + else if (su.ss.ss_family == AF_INET6) { + addr_str = g_malloc0 (INET6_ADDRSTRLEN + 1); + /* XXX: support ipv6 addresses here */ + addr.s_addr = INADDR_NONE; + inet_ntop (AF_INET6, &su.s6.sin6_addr, addr_str, INET6_ADDRSTRLEN); + msg_info ("accepted connection from [%s] port %d", + addr_str, ntohs (su.s6.sin6_port)); + } + else { + addr.s_addr = INADDR_NONE; + msg_err ("accepted connection from unsupported address family: %d", su.ss.ss_family); + close (nfd); + return; + } /* Call finalizer function */ lua_rawgeti (L, LUA_REGISTRYINDEX, ctx->cbref_accept); diff --git a/src/plugins/regexp.c b/src/plugins/regexp.c index 272805548..91543d2c4 100644 --- a/src/plugins/regexp.c +++ b/src/plugins/regexp.c @@ -1151,7 +1151,8 @@ optimize_regexp_expression (struct expression **e, GQueue * stack, gboolean res) } static gboolean -process_regexp_expression (struct expression *expr, gchar *symbol, struct worker_task *task, const gchar *additional, struct lua_locked_state *nL) +process_regexp_expression (struct expression *expr, gchar *symbol, struct worker_task *task, + const gchar *additional, struct lua_locked_state *nL) { GQueue *stack; gsize cur, op1, op2; @@ -1192,15 +1193,13 @@ process_regexp_expression (struct expression *expr, gchar *symbol, struct worker } else if (it->type == EXPR_STR) { /* This may be lua function, try to call it */ - if (regexp_module_ctx->workers != NULL) { - if (nL) { - rspamd_mutex_lock (nL->m); - cur = maybe_call_lua_function ((const gchar*)it->content.operand, task, nL->L); - rspamd_mutex_unlock (nL->m); - } - else { - cur = maybe_call_lua_function ((const gchar*)it->content.operand, task, task->cfg->lua_state); - } + if (nL) { + rspamd_mutex_lock (nL->m); + cur = maybe_call_lua_function ((const gchar*)it->content.operand, task, nL->L); + rspamd_mutex_unlock (nL->m); + } + else { + cur = maybe_call_lua_function ((const gchar*)it->content.operand, task, task->cfg->lua_state); } debug_task ("function %s returned %s", (const gchar *)it->content.operand, cur ? "true" : "false"); if (try_optimize) { diff --git a/src/protocol.c b/src/protocol.c index 151b59a9f..ffc56bde6 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -1141,12 +1141,12 @@ print_metric_data_json (struct worker_task *task, gchar *outbuf, gsize size, gint r = 0; gchar *local_act; - if (task->pre_result.action == METRIC_ACTION_NOACTION) { - local_act = "False"; - } - else if (task->pre_result.action <= METRIC_ACTION_SOFT_REJECT) { + if (task->pre_result.action <= METRIC_ACTION_SOFT_REJECT) { local_act = "True"; } + else { + local_act = "False"; + } if (metric_res == NULL) { /* This is case when we got reject result from pre filters */ r = rspamd_snprintf (outbuf, size, diff --git a/src/smtp_proxy.c b/src/smtp_proxy.c index e7856898d..e90be31fe 100644 --- a/src/smtp_proxy.c +++ b/src/smtp_proxy.c @@ -217,7 +217,9 @@ free_smtp_proxy_session (gpointer arg) if (session->state != SMTP_PROXY_STATE_PROXY && session->state != SMTP_PROXY_STATE_REJECT && session->state != SMTP_PROXY_STATE_REJECT_EMULATE) { /* Send 521 fatal error */ - write (session->sock, fatal_smtp_error, sizeof (fatal_smtp_error)); + if (write (session->sock, fatal_smtp_error, sizeof (fatal_smtp_error)) == -1) { + msg_err ("write error to client failed: %s", strerror (errno)); + } } else if ((session->state == SMTP_PROXY_STATE_REJECT || session->state == SMTP_PROXY_STATE_REJECT_EMULATE) && session->from && session->rcpt && session->dnsbl_applied) { -- 2.39.5