aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2010-10-11 18:39:56 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2010-10-11 18:39:56 +0400
commitdbee2f63ee747b5d4247038f27566bc5aebfe3b7 (patch)
treec2d60701691ab106e593be24a6974ab7dc0e6fa1
parentb0ce5fefb9e694083846af1e45b09f4baa4b0446 (diff)
downloadrspamd-dbee2f63ee747b5d4247038f27566bc5aebfe3b7.tar.gz
rspamd-dbee2f63ee747b5d4247038f27566bc5aebfe3b7.zip
Fixes bugs found with clang-static analyser.
Strictly follow c99 standart. Turn on pedantic c99 checks.
-rw-r--r--CMakeLists.txt14
-rw-r--r--src/binlog.c6
-rw-r--r--src/buffer.c42
-rw-r--r--src/cfg_utils.c18
-rw-r--r--src/cfg_xml.c3
-rw-r--r--src/classifiers/bayes.c1
-rw-r--r--src/classifiers/winnow.c15
-rw-r--r--src/controller.c6
-rw-r--r--src/dns.c9
-rw-r--r--src/expressions.c16
-rw-r--r--src/fuzzy_storage.c3
-rw-r--r--src/logger.h23
-rw-r--r--src/mem_pool.c58
-rw-r--r--src/plugins/custom/ipmark/CMakeLists.txt2
-rw-r--r--src/plugins/regexp.c2
-rw-r--r--src/plugins/surbl.c13
-rw-r--r--src/protocol.h2
-rw-r--r--src/smtp.c6
-rw-r--r--src/upstream.c6
-rw-r--r--src/url.c4
20 files changed, 154 insertions, 95 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 23d7f7671..fce341a0a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -422,6 +422,7 @@ ENDIF(ENABLE_OPTIMIZATION MATCHES "ON")
# Process with warn flags
CHECK_C_COMPILER_FLAG(-Wall SUPPORT_WALL)
+CHECK_C_COMPILER_FLAG(-Wall SUPPORT_W)
CHECK_C_COMPILER_FLAG(-Wpointer-arith SUPPORT_WPOINTER)
CHECK_C_COMPILER_FLAG(-Wno-unused-parameter SUPPORT_WPARAM)
CHECK_C_COMPILER_FLAG(-Wno-unused-function SUPPORT_WFUNCTION)
@@ -429,9 +430,14 @@ CHECK_C_COMPILER_FLAG(-Wno-sign-compare SUPPORT_WSIGNCOMPARE)
CHECK_C_COMPILER_FLAG(-Wunused-variable SUPPORT_WUNUSED_VAR)
CHECK_C_COMPILER_FLAG(-Wno-declaration-after-statement SUPPORT_WDECL)
CHECK_C_COMPILER_FLAG(-Wno-pointer-sign SUPPORT_WPOINTER_SIGN)
+CHECK_C_COMPILER_FLAG(-pedantic SUPPORT_PEDANTIC_FLAG)
+CHECK_C_COMPILER_FLAG("-std=c99" SUPPORT_STD_FLAG)
-SET(CMAKE_C_WARN_FLAGS "-W")
+SET(CMAKE_C_WARN_FLAGS "")
+IF(SUPPORT_W)
+ SET(CMAKE_C_WARN_FLAGS "${CMAKE_C_WARN_FLAGS} -W")
+ENDIF(SUPPORT_W)
IF(SUPPORT_WALL)
SET(CMAKE_C_WARN_FLAGS "${CMAKE_C_WARN_FLAGS} -Wall")
ENDIF(SUPPORT_WALL)
@@ -456,6 +462,12 @@ ENDIF(SUPPORT_WDECL)
IF(SUPPORT_WPOINTER_SIGN)
SET(CMAKE_C_WARN_FLAGS "${CMAKE_C_WARN_FLAGS} -Wno-pointer-sign")
ENDIF(SUPPORT_WPOINTER_SIGN)
+IF(SUPPORT_PEDANTIC_FLAG)
+ SET(CMAKE_C_WARN_FLAGS "${CMAKE_C_WARN_FLAGS} -pedantic")
+ENDIF(SUPPORT_PEDANTIC_FLAG)
+IF(SUPPORT_STD_FLAG)
+ SET(CMAKE_C_WARN_FLAGS "${CMAKE_C_WARN_FLAGS} -std=c99")
+ENDIF(SUPPORT_STD_FLAG)
SET(CMAKE_C_FLAGS "${CMAKE_C_OPT_FLAGS} ${CMAKE_C_FLAGS} ${CMAKE_C_WARN_FLAGS}")
diff --git a/src/binlog.c b/src/binlog.c
index d3b34b7c0..955ddc68a 100644
--- a/src/binlog.c
+++ b/src/binlog.c
@@ -361,7 +361,7 @@ binlog_insert (struct rspamd_binlog *log, GTree *nodes)
off_t seek;
if (!log || !log->metaindex || !log->cur_idx || !nodes) {
- msg_info ("improperly opened binlog: %s", log->filename);
+ msg_info ("improperly opened binlog: %s", log != NULL ? log->filename : "unknown");
return FALSE;
}
@@ -380,7 +380,7 @@ binlog_insert (struct rspamd_binlog *log, GTree *nodes)
/* Check metaindex free space */
if (log->metaindex->last_index < METAINDEX_LEN) {
/* Create new index block */
- if ((seek = lseek (log->fd, 0, SEEK_END)) == -1) {
+ if ((seek = lseek (log->fd, 0, SEEK_END)) == (off_t)-1) {
msg_info ("cannot seek in file: %s, error: %s", log->filename, strerror (errno));
return FALSE;
}
@@ -407,7 +407,7 @@ binlog_sync (struct rspamd_binlog *log, guint64 from_rev, guint64 *from_time, GB
gboolean idx_mapped = FALSE, res = TRUE, is_first = FALSE;
if (!log || !log->metaindex || !log->cur_idx) {
- msg_info ("improperly opened binlog: %s", log->filename);
+ msg_info ("improperly opened binlog: %s", log != NULL ? log->filename : "unknown");
return FALSE;
}
diff --git a/src/buffer.c b/src/buffer.c
index 45b788ca9..f19d49e5d 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -27,6 +27,7 @@
#include "main.h"
#define G_DISPATCHER_ERROR dispatcher_error_quark()
+#define debug_ip(...) rspamd_conditional_debug(d->peer_addr, __FUNCTION__, __VA_ARGS__)
static void dispatcher_cb (gint fd, short what, void *arg);
@@ -60,7 +61,7 @@ sendfile_callback (rspamd_io_dispatcher_t *d)
}
}
else {
- debug_ip (d->peer_addr, "partially write data, retry");
+ debug_ip("partially write data, retry");
/* Wait for other event */
d->offset += off;
event_del (d->ev);
@@ -71,7 +72,7 @@ sendfile_callback (rspamd_io_dispatcher_t *d)
else {
if (d->write_callback) {
if (!d->write_callback (d->user_data)) {
- debug_ip (d->peer_addr, "callback set wanna_die flag, terminating");
+ debug_ip("callback set wanna_die flag, terminating");
return FALSE;
}
}
@@ -93,7 +94,7 @@ sendfile_callback (rspamd_io_dispatcher_t *d)
}
}
else {
- debug_ip (d->peer_addr, "partially write data, retry");
+ debug_ip("partially write data, retry");
/* Wait for other event */
event_del (d->ev);
event_set (d->ev, d->fd, EV_WRITE, dispatcher_cb, (void *)d);
@@ -101,7 +102,7 @@ sendfile_callback (rspamd_io_dispatcher_t *d)
}
}
else if (r + d->offset < d->file_size) {
- debug_ip (d->peer_addr, "partially write data, retry");
+ debug_ip("partially write data, retry");
/* Wait for other event */
event_del (d->ev);
event_set (d->ev, d->fd, EV_WRITE, dispatcher_cb, (void *)d);
@@ -110,7 +111,7 @@ sendfile_callback (rspamd_io_dispatcher_t *d)
else {
if (d->write_callback) {
if (!d->write_callback (d->user_data)) {
- debug_ip (d->peer_addr, "callback set wanna_die flag, terminating");
+ debug_ip("callback set wanna_die flag, terminating");
return FALSE;
}
}
@@ -132,7 +133,7 @@ sendfile_callback (rspamd_io_dispatcher_t *d)
}
}
else {
- debug_ip (d->peer_addr, "partially write data, retry");
+ debug_ip("partially write data, retry");
/* Wait for other event */
event_del (d->ev);
event_set (d->ev, d->fd, EV_WRITE, dispatcher_cb, (void *)d);
@@ -141,7 +142,7 @@ sendfile_callback (rspamd_io_dispatcher_t *d)
}
else if (r + d->offset < d->file_size) {
d->offset += r;
- debug_ip (d->peer_addr, "partially write data, retry");
+ debug_ip("partially write data, retry");
/* Wait for other event */
event_del (d->ev);
event_set (d->ev, d->fd, EV_WRITE, dispatcher_cb, (void *)d);
@@ -150,7 +151,7 @@ sendfile_callback (rspamd_io_dispatcher_t *d)
else {
if (d->write_callback) {
if (!d->write_callback (d->user_data)) {
- debug_ip (d->peer_addr, "callback set wanna_die flag, terminating");
+ debug_ip("callback set wanna_die flag, terminating");
return FALSE;
}
}
@@ -197,7 +198,7 @@ write_buffers (gint fd, rspamd_io_dispatcher_t * d, gboolean is_delayed)
buf->pos += r;
if (BUFREMAIN (buf) != 0) {
/* Continue with this buffer */
- debug_ip (d->peer_addr, "wrote %z bytes of %z", r, buf->data->len);
+ debug_ip("wrote %z bytes of %z", r, buf->data->len);
continue;
}
}
@@ -210,7 +211,7 @@ write_buffers (gint fd, rspamd_io_dispatcher_t * d, gboolean is_delayed)
}
}
else if (r == -1 && errno == EAGAIN) {
- debug_ip (d->peer_addr, "partially write data, retry");
+ debug_ip("partially write data, retry");
/* Wait for other event */
event_del (d->ev);
event_set (d->ev, fd, EV_WRITE, dispatcher_cb, (void *)d);
@@ -225,11 +226,11 @@ write_buffers (gint fd, rspamd_io_dispatcher_t * d, gboolean is_delayed)
g_list_free (d->out_buffers);
d->out_buffers = NULL;
- debug_ip (d->peer_addr, "all buffers were written successfully");
+ debug_ip("all buffers were written successfully");
if (is_delayed && d->write_callback) {
if (!d->write_callback (d->user_data)) {
- debug_ip (d->peer_addr, "callback set wanna_die flag, terminating");
+ debug_ip("callback set wanna_die flag, terminating");
return FALSE;
}
}
@@ -305,7 +306,7 @@ read_buffers (gint fd, rspamd_io_dispatcher_t * d, gboolean skip_read)
}
}
else if (r == -1 && errno == EAGAIN) {
- debug_ip (d->peer_addr, "partially read data, retry");
+ debug_ip("partially read data, retry");
return;
}
else {
@@ -313,7 +314,7 @@ read_buffers (gint fd, rspamd_io_dispatcher_t * d, gboolean skip_read)
d->in_buf->pos += r;
d->in_buf->data->len += r;
}
- debug_ip (d->peer_addr, "read %z characters, policy is %s, watermark is: %z", r,
+ debug_ip("read %z characters, policy is %s, watermark is: %z", r,
d->policy == BUFFER_LINE ? "LINE" : "CHARACTER", d->nchars);
}
@@ -403,14 +404,13 @@ read_buffers (gint fd, rspamd_io_dispatcher_t * d, gboolean skip_read)
d->in_buf->data->len = len;
d->in_buf->pos = d->in_buf->data->begin + len;
b = d->in_buf->data->begin;
- c = b;
}
else {
d->in_buf->data->len = 0;
d->in_buf->pos = d->in_buf->data->begin;
}
if (d->policy != saved_policy && len != r) {
- debug_ip (d->peer_addr, "policy changed during callback, restart buffer's processing");
+ debug_ip("policy changed during callback, restart buffer's processing");
read_buffers (fd, d, TRUE);
return;
}
@@ -425,7 +425,7 @@ read_buffers (gint fd, rspamd_io_dispatcher_t * d, gboolean skip_read)
return;
}
if (d->policy != saved_policy) {
- debug_ip (d->peer_addr, "policy changed during callback, restart buffer's processing");
+ debug_ip("policy changed during callback, restart buffer's processing");
read_buffers (fd, d, TRUE);
return;
}
@@ -444,7 +444,7 @@ dispatcher_cb (gint fd, short what, void *arg)
rspamd_io_dispatcher_t *d = (rspamd_io_dispatcher_t *) arg;
GError *err;
- debug_ip (d->peer_addr, "in dispatcher callback, what: %d, fd: %d", (gint)what, fd);
+ debug_ip("in dispatcher callback, what: %d, fd: %d", (gint)what, fd);
switch (what) {
case EV_TIMEOUT:
@@ -562,7 +562,7 @@ rspamd_set_dispatcher_policy (rspamd_io_dispatcher_t * d, enum io_policy policy,
}
}
- debug_ip (d->peer_addr, "new input length watermark is %uz", d->nchars);
+ debug_ip("new input length watermark is %uz", d->nchars);
}
gboolean
@@ -594,7 +594,7 @@ rspamd_dispatcher_write (rspamd_io_dispatcher_t * d, void *data, size_t len, gbo
d->out_buffers = g_list_prepend (d->out_buffers, newbuf);
if (!delayed) {
- debug_ip (d->peer_addr, "plan write event");
+ debug_ip("plan write event");
return write_buffers (d->fd, d, FALSE);
}
return TRUE;
@@ -640,6 +640,8 @@ rspamd_dispatcher_restore (rspamd_io_dispatcher_t * d)
event_add (d->ev, d->tv);
}
+#undef debug_ip
+
/*
* vi:ts=4
*/
diff --git a/src/cfg_utils.c b/src/cfg_utils.c
index 7e8bb3abc..27af7911a 100644
--- a/src/cfg_utils.c
+++ b/src/cfg_utils.c
@@ -718,21 +718,17 @@ internal_normalizer_func (struct config_file *cfg, long double score, void *data
long double max = *(double *)data;
if (score < 0) {
- return score;
+ return score;
}
- else {
#ifdef HAVE_TANHL
- return max * tanhl (score / max);
+ return max * tanhl (score / max);
#else
- /*
- * As some implementations of libm does not support tanhl, try to use
- * tanh
- */
- return max * tanh ((double) (score / max));
+ /*
+ * As some implementations of libm does not support tanhl, try to use
+ * tanh
+ */
+ return max * tanh ((double) (score / max));
#endif
- }
-
- return score;
}
static gboolean
diff --git a/src/cfg_xml.c b/src/cfg_xml.c
index cf09dbe65..a631e26cd 100644
--- a/src/cfg_xml.c
+++ b/src/cfg_xml.c
@@ -790,7 +790,6 @@ gboolean
handle_module_opt (struct config_file *cfg, struct rspamd_xml_userdata *ctx, GHashTable *attrs, gchar *data, gpointer user_data, gpointer dest_struct, gint offset)
{
gchar *name, *val;
- GList *cur_opt;
struct module_opt *cur;
gboolean is_lua = FALSE;
@@ -805,7 +804,7 @@ handle_module_opt (struct config_file *cfg, struct rspamd_xml_userdata *ctx, GHa
is_lua = TRUE;
}
}
- cur_opt = ctx->section_pointer;
+
/* Insert option */
cur = memory_pool_alloc0 (cfg->cfg_pool, sizeof (struct module_opt));
cur->param = name;
diff --git a/src/classifiers/bayes.c b/src/classifiers/bayes.c
index 1ce36e0bd..7bc3fde54 100644
--- a/src/classifiers/bayes.c
+++ b/src/classifiers/bayes.c
@@ -282,6 +282,7 @@ bayes_learn (struct classifier_ctx* ctx, statfile_pool_t *pool, const char *symb
1, /* error code */
"cannot find statfile for symbol: %s",
symbol);
+ return FALSE;
}
if ((to_learn = statfile_pool_is_open (pool, sel_st->path)) == NULL) {
if ((to_learn = statfile_pool_open (pool, sel_st->path, sel_st->size, FALSE)) == NULL) {
diff --git a/src/classifiers/winnow.c b/src/classifiers/winnow.c
index f1f991486..b7fe4e123 100644
--- a/src/classifiers/winnow.c
+++ b/src/classifiers/winnow.c
@@ -361,9 +361,9 @@ winnow_learn (struct classifier_ctx *ctx, statfile_pool_t *pool, const char *sym
};
char *value;
int nodes, minnodes, iterations = 0;
- struct statfile *st, *sel_st;
+ struct statfile *st, *sel_st = NULL;
stat_file_t *sel = NULL, *to_learn;
- long double res = 0., max = 0., start_value, end_value;
+ long double res = 0., max = 0., start_value = 0., end_value = 0.;
double learn_threshold = 0.0;
GList *cur, *to_demote = NULL;
gboolean force_learn = FALSE;
@@ -432,6 +432,17 @@ winnow_learn (struct classifier_ctx *ctx, statfile_pool_t *pool, const char *sym
}
cur = g_list_next (cur);
}
+
+ if (sel_st == NULL) {
+ g_set_error (err,
+ winnow_error_quark(), /* error domain */
+ 1, /* error code */
+ "cannot find statfile for symbol %s",
+ symbol);
+ msg_err ("cannot find statfile for symbol %s", symbol);
+ return FALSE;
+ }
+
to_learn = statfile_pool_is_open (pool, sel_st->path);
if (to_learn == NULL) {
g_set_error (err,
diff --git a/src/controller.c b/src/controller.c
index 9f274bc65..42c034013 100644
--- a/src/controller.c
+++ b/src/controller.c
@@ -258,7 +258,7 @@ process_sync_command (struct controller_session *session, gchar **args)
gchar out_buf[BUFSIZ], *arg, *err_str, *symbol;
gint r;
guint64 rev, time;
- struct statfile *st;
+ struct statfile *st = NULL;
struct classifier_config *ccf;
GList *cur;
struct rspamd_binlog *binlog;
@@ -591,7 +591,9 @@ process_command (struct controller_command *cmd, gchar **cmd_args, struct contro
return FALSE;
}
}
- session->learn_multiplier = strtod (arg, NULL);
+ else {
+ session->learn_multiplier = strtod (arg, NULL);
+ }
break;
default:
r = rspamd_snprintf (out_buf, sizeof (out_buf), "tokenizer is not defined" CRLF);
diff --git a/src/dns.c b/src/dns.c
index 57c955005..74a765b33 100644
--- a/src/dns.c
+++ b/src/dns.c
@@ -290,13 +290,13 @@ struct dns_name_table {
};
static gboolean
-try_compress_label (memory_pool_t *pool, guint8 *target, guint8 *start, guint8 len, guint8 *label, GList *table)
+try_compress_label (memory_pool_t *pool, guint8 *target, guint8 *start, guint8 len, guint8 *label, GList **table)
{
GList *cur;
struct dns_name_table *tbl;
guint16 pointer;
- cur = table;
+ cur = *table;
while (cur) {
tbl = cur->data;
if (tbl->len == len) {
@@ -314,7 +314,7 @@ try_compress_label (memory_pool_t *pool, guint8 *target, guint8 *start, guint8 l
tbl->off = target - start;
tbl->label = label;
tbl->len = len;
- table = g_list_prepend (table, tbl);
+ *table = g_list_prepend (*table, tbl);
return FALSE;
}
@@ -378,7 +378,7 @@ format_dns_name (struct rspamd_dns_request *req, const gchar *name, guint namele
continue;
}
/* First try to compress name */
- if (! try_compress_label (req->pool, pos, req->packet, end - begin, begin, table)) {
+ if (! try_compress_label (req->pool, pos, req->packet, end - begin, begin, &table)) {
*pos++ = (guint8)label_len;
memcpy (pos, begin, label_len);
pos += label_len;
@@ -406,7 +406,6 @@ format_dns_name (struct rspamd_dns_request *req, const gchar *name, guint namele
*pos++ = (guint8)label_len;
memcpy (pos, begin, label_len);
pos += label_len;
- remain -= label_len + 1;
break;
}
if (remain == 0) {
diff --git a/src/expressions.c b/src/expressions.c
index e9e98551c..9d17a146c 100644
--- a/src/expressions.c
+++ b/src/expressions.c
@@ -309,7 +309,7 @@ parse_expression (memory_pool_t * pool, gchar *line)
{
struct expression *expr = NULL;
struct expression_stack *stack = NULL;
- struct expression_function *func = NULL, *old;
+ struct expression_function *func = NULL;
struct expression *arg;
GQueue *function_stack;
gchar *p, *c, *str, op, *copy;
@@ -490,7 +490,7 @@ parse_expression (memory_pool_t * pool, gchar *line)
if (!in_regexp) {
/* Append argument to list */
if (*p == ',' || (*p == ')' && brackets == 0)) {
- arg = memory_pool_alloc (pool, sizeof (struct expression));
+ arg = NULL;
str = memory_pool_alloc (pool, p - c + 1);
g_strlcpy (str, c, (p - c + 1));
g_strstrip (str);
@@ -500,7 +500,6 @@ parse_expression (memory_pool_t * pool, gchar *line)
/* Pop function */
if (*p == ')') {
/* Last function in chain, goto skipping spaces state */
- old = func;
func = g_queue_pop_tail (function_stack);
if (g_queue_get_length (function_stack) == 0) {
state = SKIP_SPACES;
@@ -551,6 +550,11 @@ parse_regexp (memory_pool_t * pool, gchar *line, gboolean raw_mode)
gint regexp_flags = G_REGEX_OPTIMIZE | G_REGEX_NO_AUTO_CAPTURE;
GError *err = NULL;
+ if (line == NULL) {
+ msg_err ("cannot parse NULL line");
+ return NULL;
+ }
+
src = line;
result = memory_pool_alloc0 (pool, sizeof (struct rspamd_regexp));
/* Skip whitespaces */
@@ -577,10 +581,8 @@ parse_regexp (memory_pool_t * pool, gchar *line, gboolean raw_mode)
}
}
else {
- *begin = '\0';
result->header = memory_pool_strdup (pool, line);
result->type = REGEXP_HEADER;
- *begin = '=';
line = begin;
}
/* Find begin of regexp */
@@ -1086,8 +1088,8 @@ rspamd_content_type_has_param (struct worker_task * task, GList * args, void *un
#endif
debug_task ("checking %s param", param_name);
-
- if ((param_data = g_mime_content_type_get_parameter ((GMimeContentType *)ct, param_name)) == NULL) {
+ param_data = g_mime_content_type_get_parameter ((GMimeContentType *)ct, param_name);
+ if (param_data == NULL) {
return FALSE;
}
}
diff --git a/src/fuzzy_storage.c b/src/fuzzy_storage.c
index d967fcfe2..1bbe0dd3c 100644
--- a/src/fuzzy_storage.c
+++ b/src/fuzzy_storage.c
@@ -646,7 +646,8 @@ process_fuzzy_command (struct fuzzy_session *session)
switch (session->cmd.cmd) {
case FUZZY_CHECK:
- if ((r = process_check_command (&session->cmd, &flag))) {
+ r = process_check_command (&session->cmd, &flag);
+ if (r != 0) {
r = rspamd_snprintf (buf, sizeof (buf), "OK %d %d" CRLF, r, flag);
if (sendto (session->fd, buf, r, 0, (struct sockaddr *)&session->sa, session->salen) == -1) {
msg_err ("error while writing reply: %s", strerror (errno));
diff --git a/src/logger.h b/src/logger.h
index 84c8a41ff..f2adf65c6 100644
--- a/src/logger.h
+++ b/src/logger.h
@@ -4,6 +4,7 @@
#include "config.h"
#include "cfg_file.h"
#include "radix.h"
+#include "util.h"
/**
* Process type: main or worker
@@ -76,18 +77,18 @@ void rspamd_log_nodebug ();
/* Logging in postfix style */
#if (defined(RSPAMD_MAIN) || defined(RSPAMD_LIB) || defined(RSPAMD_TEST))
-#define msg_err(args...) rspamd_common_log_function(G_LOG_LEVEL_CRITICAL, __FUNCTION__, ##args)
-#define msg_warn(args...) rspamd_common_log_function(G_LOG_LEVEL_WARNING, __FUNCTION__, ##args)
-#define msg_info(args...) rspamd_common_log_function(G_LOG_LEVEL_INFO, __FUNCTION__, ##args)
-#define msg_debug(args...) rspamd_conditional_debug(-1, __FUNCTION__, ##args)
-#define debug_task(args...) rspamd_conditional_debug(task->from_addr.s_addr, __FUNCTION__, ##args)
-#define debug_ip(ip, args...) rspamd_conditional_debug((ip), __FUNCTION__, ##args)
+#define msg_err(...) rspamd_common_log_function(G_LOG_LEVEL_CRITICAL, __FUNCTION__, __VA_ARGS__)
+#define msg_warn(...) rspamd_common_log_function(G_LOG_LEVEL_WARNING, __FUNCTION__, __VA_ARGS__)
+#define msg_info(...) rspamd_common_log_function(G_LOG_LEVEL_INFO, __FUNCTION__, __VA_ARGS__)
+#define msg_debug(...) rspamd_conditional_debug(-1, __FUNCTION__, __VA_ARGS__)
+#define debug_task(...) rspamd_conditional_debug(task->from_addr.s_addr, __FUNCTION__, __VA_ARGS__)
+
#else
-#define msg_err(args...) fprintf(stderr, ##args)
-#define msg_warn(args...) fprintf(stderr, ##args)
-#define msg_info(args...) fprintf(stderr, ##args)
-#define msg_debug(args...) fprintf(stderr, ##args)
-#define debug_task(args...) fprintf(stderr, ##args)
+#define msg_err(...) rspamd_fprintf(stderr, __VA_ARGS__)
+#define msg_warn(...) rspamd_fprintf(stderr, __VA_ARGS__)
+#define msg_info(...) rspamd_fprintf(stderr, __VA_ARGS__)
+#define msg_debug(...) rspamd_fprintf(stderr, __VA_ARGS__)
+#define debug_task(...) rspamd_fprintf(stderr, __VA_ARGS__)
#endif
#endif
diff --git a/src/mem_pool.c b/src/mem_pool.c
index 5487b6768..63fe77809 100644
--- a/src/mem_pool.c
+++ b/src/mem_pool.c
@@ -25,6 +25,7 @@
#include "config.h"
#include "mem_pool.h"
#include "fstring.h"
+#include "logger.h"
/* Sleep time for spin lock in nanoseconds */
#define MUTEX_SLEEP_TIME 10000000L
@@ -57,15 +58,20 @@ pool_chain_new (gsize size)
{
struct _pool_chain *chain;
- g_assert (size > 0);
+ g_return_val_if_fail (size > 0, NULL);
chain = g_slice_alloc (sizeof (struct _pool_chain));
- g_assert (chain != NULL);
+ if (chain == NULL) {
+ msg_err ("cannot allocate %z bytes, aborting", sizeof (struct _pool_chain));
+ abort ();
+ }
chain->begin = g_slice_alloc (size);
-
- g_assert (chain->begin != NULL);
+ if (chain->begin == NULL) {
+ msg_err ("cannot allocate %z bytes, aborting", size);
+ abort ();
+ }
chain->len = size;
chain->pos = chain->begin;
@@ -81,10 +87,15 @@ static struct _pool_chain_shared *
pool_chain_new_shared (gsize size)
{
struct _pool_chain_shared *chain;
+ gpointer map;
#if defined(HAVE_MMAP_ANON)
- chain = (struct _pool_chain_shared *)mmap (NULL, size + sizeof (struct _pool_chain_shared), PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, -1, 0);
- g_assert (chain != MAP_FAILED);
+ map = mmap (NULL, size + sizeof (struct _pool_chain_shared), PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, -1, 0);
+ if (map == MAP_FAILED) {
+ msg_err ("cannot allocate %z bytes, aborting", size + sizeof (struct _pool_chain));
+ abort ();
+ }
+ chain = (struct _pool_chain_shared *)map;
chain->begin = ((u_char *) chain) + sizeof (struct _pool_chain_shared);
#elif defined(HAVE_MMAP_ZERO)
gint fd;
@@ -93,8 +104,12 @@ pool_chain_new_shared (gsize size)
if (fd == -1) {
return NULL;
}
- chain = (struct _pool_chain_shared *)mmap (NULL, size + sizeof (struct _pool_chain_shared), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
- g_assert (chain != MAP_FAILED);
+ map = mmap (NULL, size + sizeof (struct _pool_chain_shared), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+ if (map == MAP_FAILED) {
+ msg_err ("cannot allocate %z bytes, aborting", size + sizeof (struct _pool_chain));
+ abort ();
+ }
+ chain = (struct _pool_chain_shared *)map;
chain->begin = ((u_char *) chain) + sizeof (struct _pool_chain_shared);
#else
# error No mmap methods are defined
@@ -120,27 +135,39 @@ memory_pool_t *
memory_pool_new (gsize size)
{
memory_pool_t *new;
+ gpointer map;
- g_assert (size > 0);
+ g_return_val_if_fail (size > 0, NULL);
/* Allocate statistic structure if it is not allocated before */
if (mem_pool_stat == NULL) {
#if defined(HAVE_MMAP_ANON)
- mem_pool_stat = (memory_pool_stat_t *)mmap (NULL, sizeof (memory_pool_stat_t), PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, -1, 0);
- g_assert (stat != MAP_FAILED);
+ map = mmap (NULL, sizeof (memory_pool_stat_t), PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, -1, 0);
+ if (map == MAP_FAILED) {
+ msg_err ("cannot allocate %z bytes, aborting", sizeof (memory_pool_stat_t));
+ abort ();
+ }
+ mem_pool_stat = (memory_pool_stat_t *)map;
#elif defined(HAVE_MMAP_ZERO)
gint fd;
fd = open ("/dev/zero", O_RDWR);
g_assert (fd != -1);
- mem_pool_stat = (memory_pool_stat_t *)mmap (NULL, sizeof (memory_pool_stat_t), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
- g_assert (chain != MAP_FAILED);
+ map = mmap (NULL, sizeof (memory_pool_stat_t), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+ if (map == MAP_FAILED) {
+ msg_err ("cannot allocate %z bytes, aborting", sizeof (memory_pool_stat_t));
+ abort ();
+ }
+ mem_pool_stat = (memory_pool_stat_t *)map;
#else
# error No mmap methods are defined
#endif
}
new = g_slice_alloc (sizeof (memory_pool_t));
- g_assert (new != NULL);
+ if (new == NULL) {
+ msg_err ("cannot allocate %z bytes, aborting", sizeof (memory_pool_t));
+ abort ();
+ }
new->cur_pool = pool_chain_new (size);
new->shared_pool = NULL;
@@ -276,7 +303,8 @@ memory_pool_alloc_shared (memory_pool_t * pool, gsize size)
struct _pool_chain_shared *new, *cur;
if (pool) {
- g_assert (size > 0);
+ g_return_val_if_fail (size > 0, NULL);
+
cur = pool->shared_pool;
if (!cur) {
cur = pool_chain_new_shared (pool->first_pool->len);
diff --git a/src/plugins/custom/ipmark/CMakeLists.txt b/src/plugins/custom/ipmark/CMakeLists.txt
index 1c1b1e64c..42785599b 100644
--- a/src/plugins/custom/ipmark/CMakeLists.txt
+++ b/src/plugins/custom/ipmark/CMakeLists.txt
@@ -4,7 +4,7 @@ SET(IPMARKSRC ipmark.c
../../../mem_pool.c
)
-ADD_LIBRARY(rspamd_ipmark MODULE ${IPMARKSRC})
+ADD_LIBRARY(rspamd_ipmark SHARED ${IPMARKSRC})
TARGET_LINK_LIBRARIES(rspamd_ipmark ${GLIB2_LIBRARIES})
INSTALL(TARGETS rspamd_ipmark DESTINATION lib)
diff --git a/src/plugins/regexp.c b/src/plugins/regexp.c
index 32ab2b58c..c70b5d232 100644
--- a/src/plugins/regexp.c
+++ b/src/plugins/regexp.c
@@ -1213,7 +1213,7 @@ rspamd_check_smtp_data (struct worker_task *task, GList * args, void *unused)
}
}
}
- else {
+ else if (arg != NULL) {
if (what != NULL) {
if (process_regexp_expression (arg->data, "regexp_check_smtp_data", task, what)) {
return TRUE;
diff --git a/src/plugins/surbl.c b/src/plugins/surbl.c
index 71fbbd55d..452b590d5 100644
--- a/src/plugins/surbl.c
+++ b/src/plugins/surbl.c
@@ -511,7 +511,7 @@ format_surbl_request (memory_pool_t * pool, f_str_t * hostname, struct suffix_it
if (append_suffix) {
- r += rspamd_snprintf (result + r, len - r, ".%s", suffix->suffix);
+ rspamd_snprintf (result + r, len - r, ".%s", suffix->suffix);
}
msg_debug ("request: %s, dots: %d, level: %d, orig: %*s", result, dots_num, level, (gint)hostname->len, hostname->begin);
@@ -797,7 +797,16 @@ redirector_callback (gint fd, short what, void *arg)
break;
case STATE_READ:
if (what == EV_READ) {
- r = read (param->sock, url_buf, sizeof (url_buf));
+ r = read (param->sock, url_buf, sizeof (url_buf) - 1);
+ if (r <= 0) {
+ msg_err ("read failed: %s from %s", strerror (errno), param->redirector->name);
+ remove_normal_event (param->task->s, free_redirector_session, param);
+ upstream_fail (&param->redirector->up, param->task->tv.tv_sec);
+ return;
+ }
+
+ url_buf[r - 1] = '\0';
+
if ((p = strstr (url_buf, "Uri: ")) != NULL) {
p += sizeof ("Uri: ") - 1;
c = p;
diff --git a/src/protocol.h b/src/protocol.h
index b950c2681..e40f6db85 100644
--- a/src/protocol.h
+++ b/src/protocol.h
@@ -7,6 +7,7 @@
#define RSPAMD_PROTOCOL_H
#include "config.h"
+#include "filter.h"
#define RSPAMD_FILTER_ERROR 1
#define RSPAMD_NETWORK_ERROR 2
@@ -27,7 +28,6 @@
#define SPAMD_ERROR "EX_ERROR"
struct worker_task;
-enum rspamd_metric_action;
struct metric;
enum rspamd_protocol {
diff --git a/src/smtp.c b/src/smtp.c
index d4abdb7f9..fd679bea7 100644
--- a/src/smtp.c
+++ b/src/smtp.c
@@ -718,7 +718,8 @@ smtp_dns_cb (struct rspamd_dns_reply *reply, void *arg)
case SMTP_STATE_RESOLVE_REVERSE:
/* Parse reverse reply and start resolve of this ip */
if (reply->code != DNS_RC_NOERROR) {
- debug_ip (session->client_addr.s_addr, "DNS error: %s", dns_strerror (reply->code));
+ rspamd_conditional_debug(session->client_addr.s_addr, __FUNCTION__,
+ "DNS error: %s", dns_strerror (reply->code));
if (reply->code == DNS_RC_NXDOMAIN) {
session->hostname = memory_pool_strdup (session->pool, "unknown");
@@ -741,7 +742,8 @@ smtp_dns_cb (struct rspamd_dns_reply *reply, void *arg)
break;
case SMTP_STATE_RESOLVE_NORMAL:
if (reply->code != DNS_RC_NOERROR) {
- debug_ip (session->client_addr.s_addr, "DNS error: %s", dns_strerror (reply->code));
+ rspamd_conditional_debug(session->client_addr.s_addr, __FUNCTION__,
+ "DNS error: %s", dns_strerror (reply->code));
if (reply->code == DNS_RC_NXDOMAIN) {
session->hostname = memory_pool_strdup (session->pool, "unknown");
diff --git a/src/upstream.c b/src/upstream.c
index 115db5137..aaefd740f 100644
--- a/src/upstream.c
+++ b/src/upstream.c
@@ -25,11 +25,6 @@
#include "config.h"
#include "upstream.h"
-#ifdef WITH_DEBUG
-# define msg_debug(args...) syslog(LOG_DEBUG, ##args)
-#else
-# define msg_debug(args...) do {} while(0)
-#endif
#ifdef _THREAD_SAFE
pthread_rwlock_t upstream_mtx = PTHREAD_RWLOCK_INITIALIZER;
@@ -510,7 +505,6 @@ get_upstream_by_hash_ketama (void *ups, size_t members, size_t msize, time_t now
#undef U_LOCK
#undef U_UNLOCK
-#undef msg_debug
/*
* vi:ts=4
*/
diff --git a/src/url.c b/src/url.c
index e32c1df97..63c31095c 100644
--- a/src/url.c
+++ b/src/url.c
@@ -961,8 +961,8 @@ url_web_end (const gchar *begin, const gchar *end, const gchar *pos, url_match_t
{
const gchar *p, *c;
gchar open_brace = '\0', close_brace = '\0';
- gint i, brace_stack;
- gboolean passwd;
+ gint i, brace_stack = 0;
+ gboolean passwd = FALSE;
guint port;
p = pos + strlen (match->pattern);