]> source.dussan.org Git - rspamd.git/commitdiff
Fix some warnings found by coverity scan.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 16 Aug 2013 22:35:50 +0000 (23:35 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 16 Aug 2013 22:35:50 +0000 (23:35 +0100)
src/expressions.c
src/fstring.c
src/fuzzy_storage.c
src/lua/lua_task.c
src/lua/lua_xmlrpc.c
src/plugins/chartable.c
src/plugins/fuzzy_check.c
src/plugins/regexp.c
src/plugins/surbl.c
src/printf.c

index 6a88514c961522ecdd9b36f929988d831112d16c..c8247e40d646cb1a5e43a4453379242b89241c70 100644 (file)
@@ -605,7 +605,7 @@ parse_regexp (memory_pool_t * pool, gchar *line, gboolean raw_mode)
        while (g_ascii_isspace (*line)) {
                line++;
        }
-       if (line == '\0') {
+       if (*line == '\0') {
                msg_warn ("got empty regexp");
                return NULL;
        }
index 9f17ac861f1f1d11bf62b35618b2a7851588f920..8028d15a327bbf3d20a64caa5a1a2bbf9b201f70 100644 (file)
@@ -398,7 +398,9 @@ fstrhash_lowercase (f_str_t * str, gboolean is_utf)
 
        if (is_utf) {
                while (end < str->begin + str->len) {
-                       g_utf8_validate (p, str->len, &end);
+                       if (!g_utf8_validate (p, str->len, &end)) {
+                               return fstrhash_lowercase (str, FALSE);
+                       }
                        while (p < end) {
                                uc = g_unichar_tolower (g_utf8_get_char (p));
                                for (j = 0; j < sizeof (gunichar); j ++) {
index 7bd950014fe26f6a50c3baa02f2ed403eabe72c4..14df0e54d49e1530d76bb5ffc0d24f28ae221271 100644 (file)
@@ -471,6 +471,7 @@ read_hashes_file (struct rspamd_worker *wrk)
                        version = (gint)header[3];
                        if (version > CURRENT_FUZZY_VERSION) {
                                msg_err ("unsupported version of fuzzy hash file: %d", version);
+                               close (fd);
                                return FALSE;
                        }
                        msg_info ("reading fuzzy hashes storage file of version %d of size %d", version, (gint)(st.st_size - sizeof (header)) / sizeof (struct rspamd_fuzzy_node));
index 014a994e0f845bcc9057e6d08a3d40e958d086f3..d78aff036e70c55a3f4b04e7d919d04f0f972aad 100644 (file)
@@ -1763,7 +1763,7 @@ lua_textpart_compare_distance (lua_State * L)
        luaL_argcheck (L, ud != NULL, 2, "'textpart' expected");
        other = ud ? *((struct mime_text_part **)ud) : NULL;
 
-       if (part->parent && part->parent == other->parent) {
+       if (other != NULL && part->parent && part->parent == other->parent) {
                parent = part->parent;
                ct = g_mime_object_get_content_type (parent);
 #ifndef GMIME24
index 57691cda5c600f8a978cb2522821786400d88b39..4608d2328677fe8e3f777e75b20d1fd14a4cb34d 100644 (file)
@@ -472,7 +472,7 @@ lua_xmlrpc_parse_table (lua_State *L, gint pos, gchar *databuf, gint pr, gsize s
                        break;
                case LUA_TTABLE:
                        /* Recursive call */
-                       r += lua_xmlrpc_parse_table (L, -1, databuf, r, sizeof (databuf));
+                       r += lua_xmlrpc_parse_table (L, -1, databuf + r, r, size);
                        break;
                }
                r += rspamd_snprintf (databuf + r, size - r, "</value></member>");
index 3f680647a6e991f319a2c3f61772fef0ee548e93..c1b8826e6ea3a4dead30871bcc1df64521948e26 100644 (file)
@@ -194,6 +194,10 @@ check_part (struct mime_text_part *part, gboolean raw_mode)
                part->script = sel;
        }
 
+       if (total == 0) {
+               return 0;
+       }
+
        return ((double)mark / (double)total) > chartable_module_ctx->threshold;
 }
 
index 33e710c90260216f368a5d67b41f959b6043c8ba..50c491730526e62f9c8756b41a95ecb938e74583 100644 (file)
@@ -584,7 +584,7 @@ ok:
                                r = rspamd_snprintf (buf, sizeof (buf), "write error: %s" CRLF "END" CRLF, (*session->err)->message);
                        }
                        g_error_free (*session->err);
-                       if (! rspamd_dispatcher_write (session->session->dispatcher, buf, r, FALSE, FALSE)) {
+                       if (r > 0 && ! rspamd_dispatcher_write (session->session->dispatcher, buf, r, FALSE, FALSE)) {
                                return;
                        }
                }
@@ -834,7 +834,7 @@ fuzzy_process_handler (struct controller_session *session, f_str_t * in)
        
 
        saved = memory_pool_alloc0 (session->session_pool, sizeof (gint));
-       err = memory_pool_alloc0 (session->session_pool, sizeof (GError **));
+       err = memory_pool_alloc0 (session->session_pool, sizeof (GError *));
        r = process_message (task);
        if (r == -1) {
                msg_warn ("processing of message failed");
index b838b1ee654dc9c399ab4f40d146fdd7819b8f54..219b5b8159f3a05ccdd76e22838f1517828c0f4b 100644 (file)
@@ -729,7 +729,6 @@ process_regexp (struct rspamd_regexp *re, struct worker_task *task, const gchar
        GError                         *err = NULL;
        struct url_regexp_param         callback_param = {
                .task = task,
-               .regexp = re->regexp,
                .re = re,
                .found = FALSE
        };
@@ -741,6 +740,7 @@ process_regexp (struct rspamd_regexp *re, struct worker_task *task, const gchar
                return 0;
        }
 
+       callback_param.regexp = re->regexp;
        if ((r = task_cache_check (task, re)) != -1) {
                debug_task ("regexp /%s/ is found in cache, result: %d", re->regexp_text, r);
                return r == 1;
@@ -2056,6 +2056,10 @@ compare_subtype (struct worker_task *task, GMimeContentType * ct, gchar *subtype
        struct rspamd_regexp           *re;
        gint                            r;
 
+       if (subtype == NULL || ct == NULL) {
+               msg_warn ("invalid parameters passed");
+               return FALSE;
+       }
        if (*subtype == '/') {
                /* This is regexp, so compile and create g_regexp object */
                if ((re = re_cache_check (subtype, task->cfg->cfg_pool)) == NULL) {
index 7125e5aa7f4188cfc1a1d98aff19b0080a2eff97..7703a73aa90f1f43b61dd90473ff1c8cf9a80fe0 100644 (file)
@@ -891,8 +891,10 @@ redirector_callback (gint fd, short what, void *arg)
                                }
                                if (found) {
                                        debug_task ("<%s> got reply from redirector: '%s' -> '%s'", param->task->message_id, struri (param->url), c);
-                                       parse_uri (param->url, memory_pool_strdup (param->task->task_pool, c), param->task->task_pool);
-                                       make_surbl_requests (param->url, param->task, param->suffix, FALSE);
+                                       r = parse_uri (param->url, memory_pool_strdup (param->task->task_pool, c), param->task->task_pool);
+                                       if (r == URI_ERRNO_OK || r == URI_ERRNO_NO_SLASHES || r == URI_ERRNO_NO_HOST_SLASH) {
+                                               make_surbl_requests (param->url, param->task, param->suffix, FALSE);
+                                       }
                                }
                        }
                        upstream_ok (&param->redirector->up, param->task->tv.tv_sec);
index 02b4ee09d558c55e4199ad4ba27f2751ee774c0b..00730d16cdd916c3cfca179258a4ee3dcc157d72 100644 (file)
@@ -28,7 +28,7 @@
 /**
  * From FreeBSD libutil code
  */
-static const int maxscale = 7;
+static const int maxscale = 6;
 
 static gchar *
 rspamd_humanize_number (gchar *buf, gchar *last, gint64 num, gboolean bytes)