]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
Fixes bugs found with clang-static analyser.
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Mon, 11 Oct 2010 14:39:56 +0000 (18:39 +0400)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Mon, 11 Oct 2010 14:39:56 +0000 (18:39 +0400)
Strictly follow c99 standart.
Turn on pedantic c99 checks.

20 files changed:
CMakeLists.txt
src/binlog.c
src/buffer.c
src/cfg_utils.c
src/cfg_xml.c
src/classifiers/bayes.c
src/classifiers/winnow.c
src/controller.c
src/dns.c
src/expressions.c
src/fuzzy_storage.c
src/logger.h
src/mem_pool.c
src/plugins/custom/ipmark/CMakeLists.txt
src/plugins/regexp.c
src/plugins/surbl.c
src/protocol.h
src/smtp.c
src/upstream.c
src/url.c

index 23d7f767149750851b1771275258ba53640c1760..fce341a0a8e40d6d5d562cd88e8db81d168198f4 100644 (file)
@@ -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}")
 
index d3b34b7c0ef1d7c5e478120f8d913511eb119906..955ddc68abf8e23fc22ae57d453c86bb0c21e352 100644 (file)
@@ -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;
        }
 
index 45b788ca992d40987b7432e3b932f51b8ec634c2..f19d49e5dc6f680c284fb943d084d4886dee8bff 100644 (file)
@@ -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 
  */
index 7e8bb3abc6991818353761b54ab4983b63c502c2..27af7911af8355a4cba22110b79b505b7e68033d 100644 (file)
@@ -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
index cf09dbe65115432826778a5942df4a15c7f053a6..a631e26cd5a5890ebb9d3fd85a5ea9720a588e8a 100644 (file)
@@ -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;
index 1ce36e0bd8bdb69889f6fe98a7a09ae8f3bd48ef..7bc3fde54c9d84a7bc1737fd1da417d889b7114c 100644 (file)
@@ -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) {
index f1f9914867a12648450fae8efcf72017f5c7b848..b7fe4e12300be4c7ac2807364f16d897b92cdf23 100644 (file)
@@ -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,
index 9f274bc65a37e8c182594ab47e701ecf84a08618..42c0340131f75b29ad69b9e0aa5a4afd38ca85f9 100644 (file)
@@ -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);
index 57c9550052a2585e9b4e42cfec3c2d312778d981..74a765b336753f76d09832927a9822bb8134987f 100644 (file)
--- 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) {
index e9e98551c2b2ab4f950c3a76060a3b9c7a77d382..9d17a146cd8c441e4b819d66d7ca9bbf60dec441 100644 (file)
@@ -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;
                }
        }
index d967fcfe28c43ec40774751c6f08382f576ae3cb..1bbe0dd3cb900c5c848c68902fec086df4f9c72e 100644 (file)
@@ -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));
index 84c8a41ff1ade3cf2aa04eb5ada418ce4f7f100a..f2adf65c695a33fc0ec982f1844f20a40f5fbe38 100644 (file)
@@ -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
index 5487b6768dd6161abb390383925c5bc185fb2a59..63fe77809f3c32070b2b39a65831178831a8e29b 100644 (file)
@@ -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);
index 1c1b1e64c170e9a5c7abe33c4bc4e0e6b4e371ee..42785599b5326b541b90a8e378d3fdb02f4842a4 100644 (file)
@@ -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)
index 32ab2b58cb11a1b03c5d77834cf1236a869e5d95..c70b5d2329063527d155e1e3ebabd07c462bf37f 100644 (file)
@@ -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;
index 71fbbd55d16614e88a89c8e4f8c887c3f547f026..452b590d56dbf9d0915e6159e3fb3837d984e050 100644 (file)
@@ -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;
index b950c2681185da4b4015397cfe6dde4dabe25bf8..e40f6db85e54f3853f7647eb8adc9bec9e716f06 100644 (file)
@@ -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 {
index d4abdb7f9a43060df449fdbadf6a8d5befdd095d..fd679bea71ec8a51859220189af8abaf43b1ac7a 100644 (file)
@@ -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");
index 115db51377bcf2adaa14d08517ccadad5bc450f7..aaefd740fb0f6f02f5f02caf2a003a8e46d96d42 100644 (file)
 #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 
  */
index e32c1df97a62f386cf2d30c5c8044c30a3dd88bf..63c31095ca6b889d8b68aa84e67cb8090b292874 100644 (file)
--- 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);