]> source.dussan.org Git - rspamd.git/commitdiff
Fix some issues found by coverity
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 9 Feb 2016 16:43:40 +0000 (16:43 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 9 Feb 2016 16:43:40 +0000 (16:43 +0000)
20 files changed:
src/libutil/addr.c
src/libutil/http.c
src/libutil/map.c
src/libutil/sqlite_utils.c
src/libutil/str_util.c
src/libutil/util.c
src/lua/lua_config.c
src/lua/lua_http.c
src/lua/lua_ip.c
src/lua/lua_logger.c
src/lua/lua_redis.c
src/lua/lua_regexp.c
src/lua/lua_task.c
src/lua/lua_trie.c
src/lua/lua_upstream.c
src/lua_worker.c
src/plugins/dkim_check.c
src/plugins/fuzzy_check.c
src/plugins/surbl.c
src/rspamadm/signtool.c

index b70de6b9d56dc1840bf240e96b6e93c604236486..e95ac4c64800a63daac0c1deaeca9e067d02505a 100644 (file)
@@ -760,16 +760,16 @@ rspamd_inet_address_listen (const rspamd_inet_addr_t *addr, gint type,
                sa = &addr->u.in.addr.sa;
        }
 
-       setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&on, sizeof (gint));
+       (void)setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&on, sizeof (gint));
 
 #ifdef HAVE_IPV6_V6ONLY
        if (addr->af == AF_INET6) {
                /* We need to set this flag to avoid errors */
                on = 1;
 #ifdef SOL_IPV6
-               setsockopt (fd, SOL_IPV6, IPV6_V6ONLY, (const void *)&on, sizeof (gint));
+               (void)setsockopt (fd, SOL_IPV6, IPV6_V6ONLY, (const void *)&on, sizeof (gint));
 #elif defined(IPPROTO_IPV6)
-               setsockopt (fd, IPPROTO_IPV6, IPV6_V6ONLY, (const void *)&on, sizeof (gint));
+               (void)setsockopt (fd, IPPROTO_IPV6, IPV6_V6ONLY, (const void *)&on, sizeof (gint));
 #endif
        }
 #endif
index 605439129c49f21b54798f02e8516bf18421e480..21b763108fb674651eefd016d1e10ad7b1dd3f5e 100644 (file)
@@ -723,6 +723,7 @@ rspamd_http_decrypt_message (struct rspamd_http_connection *conn,
 
        msg->body_buf.len = 0;
 
+       memset (&decrypted_parser, 0, sizeof (decrypted_parser));
        http_parser_init (&decrypted_parser,
                        conn->type == RSPAMD_HTTP_SERVER ? HTTP_REQUEST : HTTP_RESPONSE);
 
index 8d04fe2361b0e7a71e91be0d2b6d7a58ada3d1f0..ea5f3f2101ca8772410b83e385d1b91c0421a681 100644 (file)
@@ -802,7 +802,7 @@ rspamd_parse_abstract_list (rspamd_mempool_t * pool,
                                c = p;
                                data->state = 1;
                        }
-                       else if (*p == '\r' || *p == '\n') {
+                       else if ((*p == '\r' || *p == '\n') && p > c) {
                                /* Got EOL marker, save stored string */
                                s = strip_map_elt (pool, c, p - c);
 
index 7e80190e34e7103b4977f8e22d0f5d1143cbab64..883d26580f7f6f7820dae3761d436b236c60b972 100644 (file)
@@ -337,6 +337,13 @@ rspamd_sqlite3_open_or_create (rspamd_mempool_t *pool, const gchar *path, const
                                path, rc);
 #endif
 
+               if (has_lock && lock_fd != -1) {
+                       msg_debug_pool_check ("removing lock from %s", lock_path);
+                       rspamd_file_unlock (lock_fd, FALSE);
+                       unlink (lock_path);
+                       close (lock_fd);
+               }
+
                return NULL;
        }
 
@@ -418,7 +425,7 @@ rspamd_sqlite3_open_or_create (rspamd_mempool_t *pool, const gchar *path, const
                                sqlite3_errmsg (sqlite));
        }
 
-       if (has_lock) {
+       if (has_lock && lock_fd != -1) {
                msg_debug_pool_check ("removing lock from %s", lock_path);
                rspamd_file_unlock (lock_fd, FALSE);
                unlink (lock_path);
index 6daf839933288faa0b1fdc22c5f4cad09b60163f..89a6537deb8849aca547be57bee2214d080b0177 100644 (file)
@@ -1382,7 +1382,7 @@ gint
 rspamd_decode_hex_buf (const gchar *in, gsize inlen,
                guchar *out, gsize outlen)
 {
-       guchar *o, *end, ret;
+       guchar *o, *end, ret = 0;
        const gchar *p;
        gchar c;
 
index 19ae980c0b46ec9dae57d456def402c7b609eeab..e715c97cf82d936d11b659d538d1f13ac6d16fa1 100644 (file)
@@ -173,18 +173,25 @@ rspamd_inet_socket_create (gint type, struct addrinfo *addr, gboolean is_server,
                }
 
                if (is_server) {
-                       setsockopt (fd,
-                               SOL_SOCKET,
-                               SO_REUSEADDR,
-                               (const void *)&on,
-                               sizeof (gint));
+                       if (setsockopt (fd,
+                                       SOL_SOCKET,
+                                       SO_REUSEADDR,
+                                       (const void *)&on,
+                                       sizeof (gint)) == -1) {
+                               msg_warn ("setsockopt failed: %d, '%s'", errno,
+                                               strerror (errno));
+                       }
 #ifdef HAVE_IPV6_V6ONLY
                        if (cur->ai_family == AF_INET6) {
-                               setsockopt (fd,
-                                       IPPROTO_IPV6,
-                                       IPV6_V6ONLY,
-                                       (const void *)&on,
-                                       sizeof (gint));
+                               if (setsockopt (fd,
+                                               IPPROTO_IPV6,
+                                               IPV6_V6ONLY,
+                                               (const void *)&on,
+                                               sizeof (gint)) == -1) {
+
+                                       msg_warn ("setsockopt failed: %d, '%s'", errno,
+                                                       strerror (errno));
+                               }
                        }
 #endif
                        r = bind (fd, cur->ai_addr, cur->ai_addrlen);
@@ -218,10 +225,12 @@ rspamd_inet_socket_create (gint type, struct addrinfo *addr, gboolean is_server,
                else {
                        /* Still need to check SO_ERROR on socket */
                        optlen = sizeof (s_error);
-                       getsockopt (fd, SOL_SOCKET, SO_ERROR, (void *)&s_error, &optlen);
-                       if (s_error) {
-                               errno = s_error;
-                               goto out;
+
+                       if (getsockopt (fd, SOL_SOCKET, SO_ERROR, (void *)&s_error, &optlen) != -1) {
+                               if (s_error) {
+                                       errno = s_error;
+                                       goto out;
+                               }
                        }
                }
                if (list == NULL) {
@@ -314,8 +323,12 @@ rspamd_socket_unix (const gchar *path,
                goto out;
        }
        if (is_server) {
-               setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&on,
-                       sizeof (gint));
+               if (setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&on,
+                       sizeof (gint)) == -1) {
+                       msg_warn ("setsockopt failed: %d, '%s'", errno,
+                                       strerror (errno));
+               }
+
                r = bind (fd, (struct sockaddr *)addr, SUN_LEN (addr));
        }
        else {
@@ -348,10 +361,12 @@ rspamd_socket_unix (const gchar *path,
        else {
                /* Still need to check SO_ERROR on socket */
                optlen = sizeof (s_error);
-               getsockopt (fd, SOL_SOCKET, SO_ERROR, (void *)&s_error, &optlen);
-               if (s_error) {
-                       errno = s_error;
-                       goto out;
+
+               if (getsockopt (fd, SOL_SOCKET, SO_ERROR, (void *)&s_error, &optlen) != -1) {
+                       if (s_error) {
+                               errno = s_error;
+                               goto out;
+                       }
                }
        }
 
@@ -496,6 +511,7 @@ rspamd_sockets_list (const gchar *credits, guint16 port,
                        }
                        if (fd != -1) {
                                result = g_list_prepend (result, GINT_TO_POINTER (fd));
+                               fd = -1;
                        }
                        else {
                                goto err;
@@ -1747,12 +1763,20 @@ restart:
 
        /* Turn echo off */
        if (tcgetattr (input, &oterm) != 0) {
+               close (input);
                errno = ENOTTY;
                return 0;
        }
+
        memcpy (&term, &oterm, sizeof(term));
        term.c_lflag &= ~(ECHO | ECHONL);
-       (void)tcsetattr (input, TCSAFLUSH, &term);
+
+       if (tcsetattr (input, TCSAFLUSH, &term) == -1) {
+               errno = ENOTTY;
+               close (input);
+               return 0;
+       }
+
        (void)write (output, "Enter passphrase: ", sizeof ("Enter passphrase: ") -
                1);
 
@@ -1816,7 +1840,7 @@ restart:
                }
        }
 
-       return p - buf;
+       return (p - buf);
 #endif
 }
 
@@ -1942,7 +1966,7 @@ rspamd_init_libs (void)
                                OTTERY_ENTROPY_SRC_RDRAND);
        }
 
-       ottery_init (ottery_cfg);
+       g_assert (ottery_init (ottery_cfg) == 0);
 
 #ifdef HAVE_LOCALE_H
        if (getenv ("LANG") == NULL) {
index fa778ff6d7b23eb6087a32c881f4fa5aeb3ccd96..1ab7a746bc04b0a59c1ef75472b0ae609a8a21ce 100644 (file)
@@ -732,6 +732,7 @@ lua_config_register_pre_filter (lua_State *L)
                        cd->callback.ref = luaL_ref (L, LUA_REGISTRYINDEX);
                        cd->cb_is_ref = TRUE;
                }
+
                cd->L = L;
                cfg->pre_filters = g_list_prepend (cfg->pre_filters, cd);
                rspamd_mempool_add_destructor (cfg->cfg_pool,
@@ -753,6 +754,7 @@ lua_config_add_radix_map (lua_State *L)
                description = lua_tostring (L, 3);
                r = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (radix_compressed_t *));
                *r = radix_create_compressed ();
+
                if (!rspamd_map_add (cfg, map_line, description, rspamd_radix_read,
                        rspamd_radix_fin, (void **)r)) {
                        msg_warn_config ("invalid radix map %s", map_line);
@@ -760,7 +762,8 @@ lua_config_add_radix_map (lua_State *L)
                        lua_pushnil (L);
                        return 1;
                }
-               ud = lua_newuserdata (L, sizeof (radix_compressed_t *));
+
+               ud = lua_newuserdata (L, sizeof (radix_compressed_t **));
                *ud = r;
                rspamd_lua_setclass (L, "rspamd{radix}", -1);
 
@@ -794,7 +797,7 @@ lua_config_radix_from_config (lua_State *L)
                        r = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (radix_compressed_t *));
                        *r = radix_create_compressed ();
                        radix_add_generic_iplist (ucl_obj_tostring (obj), r);
-                       ud = lua_newuserdata (L, sizeof (radix_compressed_t *));
+                       ud = lua_newuserdata (L, sizeof (radix_compressed_t **));
                        *ud = r;
                        rspamd_lua_setclass (L, "rspamd{radix}", -1);
                        return 1;
@@ -823,6 +826,7 @@ lua_config_add_hash_map (lua_State *L)
                description = lua_tostring (L, 3);
                r = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (GHashTable *));
                *r = g_hash_table_new (rspamd_strcase_hash, rspamd_strcase_equal);
+
                if (!rspamd_map_add (cfg, map_line, description, rspamd_hosts_read, rspamd_hosts_fin,
                        (void **)r)) {
                        msg_warn ("invalid hash map %s", map_line);
@@ -830,10 +834,11 @@ lua_config_add_hash_map (lua_State *L)
                        lua_pushnil (L);
                        return 1;
                }
+
                rspamd_mempool_add_destructor (cfg->cfg_pool,
                        (rspamd_mempool_destruct_t)g_hash_table_destroy,
                        *r);
-               ud = lua_newuserdata (L, sizeof (GHashTable *));
+               ud = lua_newuserdata (L, sizeof (GHashTable **));
                *ud = r;
                rspamd_lua_setclass (L, "rspamd{hash_table}", -1);
 
@@ -857,6 +862,7 @@ lua_config_add_kv_map (lua_State *L)
                description = lua_tostring (L, 3);
                r = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (GHashTable *));
                *r = g_hash_table_new (rspamd_strcase_hash, rspamd_strcase_equal);
+
                if (!rspamd_map_add (cfg, map_line, description, rspamd_kv_list_read, rspamd_kv_list_fin,
                        (void **)r)) {
                        msg_warn_config ("invalid hash map %s", map_line);
@@ -864,10 +870,11 @@ lua_config_add_kv_map (lua_State *L)
                        lua_pushnil (L);
                        return 1;
                }
+
                rspamd_mempool_add_destructor (cfg->cfg_pool,
                        (rspamd_mempool_destruct_t)g_hash_table_destroy,
                        *r);
-               ud = lua_newuserdata (L, sizeof (GHashTable *));
+               ud = lua_newuserdata (L, sizeof (GHashTable **));
                *ud = r;
                rspamd_lua_setclass (L, "rspamd{hash_table}", -1);
 
@@ -1062,7 +1069,12 @@ lua_config_register_symbols (lua_State *L)
        gdouble weight = 1.0;
 
        if (lua_gettop (L) < 3) {
-               msg_err_config ("not enough arguments to register a function");
+               if (cfg) {
+                       msg_err_config ("not enough arguments to register a function");
+               }
+
+               lua_error (L);
+
                return 0;
        }
        if (cfg) {
@@ -1231,6 +1243,11 @@ lua_config_register_dependency (lua_State * L)
        const gchar *name = NULL, *from = NULL;
        gint id;
 
+       if (cfg == NULL) {
+               lua_error (L);
+               return 0;
+       }
+
        if (lua_type (L, 2) == LUA_TNUMBER) {
                id = luaL_checknumber (L, 2);
                name = luaL_checkstring (L, 3);
index 5f2dd241646bf5b65522b09ba803c70a501f6e3c..81656586928137f77c4ccfb213f2cb844f5bc0e3 100644 (file)
@@ -419,10 +419,6 @@ lua_http_request (lua_State *L)
                msg_err ("http request has bad params");
                lua_pushboolean (L, FALSE);
 
-               if (mime_type) {
-                       g_free (mime_type);
-               }
-
                return 1;
        }
 
@@ -434,6 +430,7 @@ lua_http_request (lua_State *L)
        cbd->mime_type = mime_type;
        msec_to_tv (timeout, &cbd->tv);
        cbd->fd = -1;
+
        if (session) {
                cbd->session = session;
                rspamd_session_add_event (session,
index 54126f22cde61f4f47e73c6c56367c5f9922f108..d82de9af9c13e0f69ede77e9f2a96d1379036283 100644 (file)
@@ -358,7 +358,10 @@ lua_ip_from_string (lua_State *L)
        ip_str = luaL_checkstring (L, 1);
        if (ip_str) {
                ip = lua_ip_new (L, NULL);
-               rspamd_parse_inet_address (&ip->addr, ip_str, 0);
+
+               if (!rspamd_parse_inet_address (&ip->addr, ip_str, 0)) {
+                       msg_warn ("cannot parse ip: %s", ip_str);
+               }
        }
        else {
                lua_pushnil (L);
@@ -525,11 +528,17 @@ rspamd_lua_ip_push_fromstring (lua_State *L, const gchar *ip_str)
        }
        else {
                ip = g_slice_alloc0 (sizeof (struct rspamd_lua_ip));
-               rspamd_parse_inet_address (&ip->addr, ip_str, 0);
 
-               pip = lua_newuserdata (L, sizeof (struct rspamd_lua_ip *));
-               rspamd_lua_setclass (L, "rspamd{ip}", -1);
-               *pip = ip;
+               if (rspamd_parse_inet_address (&ip->addr, ip_str, 0)) {
+
+                       pip = lua_newuserdata (L, sizeof (struct rspamd_lua_ip *));
+                       rspamd_lua_setclass (L, "rspamd{ip}", -1);
+                       *pip = ip;
+               }
+               else {
+                       g_slice_free1 (sizeof (*ip), ip);
+                       lua_pushnil (L);
+               }
        }
 }
 
index a28db13d21a6b389aa0f4badd069af558a33a437..8f2f62c037439223259715e943e80f698e3e318b 100644 (file)
@@ -445,48 +445,57 @@ lua_logger_logx (lua_State *L, GLogLevelFlags level, gboolean is_string)
        }
        else if (lua_type (L, 1) == LUA_TUSERDATA) {
                fmt_pos = 2;
-               lua_getmetatable (L, 1);
-               lua_pushstring (L, "__index");
-               lua_gettable (L, -2);
 
-               lua_pushstring (L, "class");
-               lua_gettable (L, -2);
+               if (lua_getmetatable (L, 1) != 0) {
+                       lua_pushstring (L, "__index");
+                       lua_gettable (L, -2);
 
-               clsname = lua_tostring (L, -1);
+                       lua_pushstring (L, "class");
+                       lua_gettable (L, -2);
 
-               if (strcmp (clsname, "rspamd{task}") == 0) {
-                       struct rspamd_task *task = lua_check_task (L, 1);
+                       clsname = lua_tostring (L, -1);
 
-                       if (task) {
-                               uid = task->task_pool->tag.uid;
+                       if (strcmp (clsname, "rspamd{task}") == 0) {
+                               struct rspamd_task *task = lua_check_task (L, 1);
+
+                               if (task) {
+                                       uid = task->task_pool->tag.uid;
+                               }
                        }
-               }
-               else if (strcmp (clsname, "rspamd{mempool}") == 0) {
-                       rspamd_mempool_t  *pool;
+                       else if (strcmp (clsname, "rspamd{mempool}") == 0) {
+                               rspamd_mempool_t  *pool;
 
-                       pool = rspamd_lua_check_mempool (L, 1);
+                               pool = rspamd_lua_check_mempool (L, 1);
 
-                       if (pool) {
-                               uid = pool->tag.uid;
+                               if (pool) {
+                                       uid = pool->tag.uid;
+                               }
                        }
-               }
-               else if (strcmp (clsname, "rspamd{config}") == 0) {
-                       struct rspamd_config *cfg;
+                       else if (strcmp (clsname, "rspamd{config}") == 0) {
+                               struct rspamd_config *cfg;
 
-                       cfg = lua_check_config (L, 1);
+                               cfg = lua_check_config (L, 1);
 
-                       if (cfg) {
-                               uid = cfg->checksum;
+                               if (cfg) {
+                                       uid = cfg->checksum;
+                               }
                        }
+
+                       /* Metatable, __index, classname */
+                       lua_pop (L, 3);
                }
+               else {
+                       lua_error (L);
 
-               /* Metatable, __index, classname */
-               lua_pop (L, 3);
+                       return 0;
+               }
        }
        else {
                /* Bad argument type */
                msg_err ("bad format string type: %s", lua_typename (L, lua_type (L,
                                1)));
+               lua_error (L);
+
                return 0;
        }
 
index 4e02107f5c75f95d80363644299c4c47cb9dafb0..cc408244a8b6d2b53838f101b6c98330dd11aa6b 100644 (file)
@@ -520,7 +520,6 @@ lua_redis_make_request (lua_State *L)
                ud->terminated = 0;
                ud->ctx = redisAsyncConnect (rspamd_inet_address_to_string (addr->addr),
                                rspamd_inet_address_get_port (addr->addr));
-               redisAsyncSetConnectCallback (ud->ctx, lua_redis_connect_cb);
 
                if (ud->ctx == NULL || ud->ctx->err) {
                        if (ud->ctx) {
@@ -534,6 +533,7 @@ lua_redis_make_request (lua_State *L)
                        return 1;
                }
 
+               redisAsyncSetConnectCallback (ud->ctx, lua_redis_connect_cb);
                redisLibeventAttach (ud->ctx, ud->task->ev_base);
                ret = redisAsyncCommandArgv (ud->ctx,
                                        lua_redis_callback,
@@ -757,7 +757,6 @@ lua_redis_connect (lua_State *L)
                ud->terminated = 0;
                ud->ctx = redisAsyncConnect (rspamd_inet_address_to_string (addr->addr),
                                rspamd_inet_address_get_port (addr->addr));
-               redisAsyncSetConnectCallback (ud->ctx, lua_redis_connect_cb);
 
                if (ud->ctx == NULL || ud->ctx->err) {
                        REF_RELEASE (ctx);
@@ -766,6 +765,7 @@ lua_redis_connect (lua_State *L)
                        return 1;
                }
 
+               redisAsyncSetConnectCallback (ud->ctx, lua_redis_connect_cb);
                redisLibeventAttach (ud->ctx, ud->task->ev_base);
                pctx = lua_newuserdata (L, sizeof (ctx));
                *pctx = ctx;
index 615062bf2d4f2aa2cd9b4158e60e68e1b6409618..9bd387a4b24b4daef89b252f3d69a4235a8b1c8f 100644 (file)
@@ -610,6 +610,12 @@ lua_regexp_split (lua_State *L)
                }
                else if (lua_type (L, 2) == LUA_TUSERDATA) {
                        t = lua_check_text (L, 2);
+
+                       if (t == NULL) {
+                               lua_error (L);
+                               return 0;
+                       }
+
                        data = t->start;
                        len = t->len;
                        is_text = TRUE;
index 3f2b0723d9aebe2b789933a153350de1fa30a424..2eaeb221dcc56dfacb35c35d4f0b16df54da4e4b 100644 (file)
@@ -681,9 +681,14 @@ lua_task_get_cfg (lua_State *L)
        struct rspamd_task *task = lua_check_task (L, 1);
        struct rspamd_config **pcfg;
 
-       pcfg = lua_newuserdata (L, sizeof (gpointer));
-       rspamd_lua_setclass (L, "rspamd{config}", -1);
-       *pcfg = task->cfg;
+       if (task) {
+               pcfg = lua_newuserdata (L, sizeof (gpointer));
+               rspamd_lua_setclass (L, "rspamd{config}", -1);
+               *pcfg = task->cfg;
+       }
+       else {
+               lua_error (L);
+       }
 
        return 1;
 }
@@ -694,8 +699,14 @@ lua_task_set_cfg (lua_State *L)
        struct rspamd_task *task = lua_check_task (L, 1);
        void *ud = luaL_checkudata (L, 2, "rspamd{config}");
 
-       luaL_argcheck (L, ud != NULL, 1, "'config' expected");
-       task->cfg = ud ? *((struct rspamd_config **)ud) : NULL;
+       if (task) {
+               luaL_argcheck (L, ud != NULL, 1, "'config' expected");
+               task->cfg = ud ? *((struct rspamd_config **)ud) : NULL;
+       }
+       else {
+               lua_error (L);
+       }
+
        return 0;
 }
 
@@ -1020,7 +1031,7 @@ lua_task_set_request_header (lua_State *L)
 
        s = luaL_checklstring (L, 2, &len);
 
-       if (s) {
+       if (s && task) {
                if (lua_type (L, 3) == LUA_TSTRING) {
                        v = luaL_checklstring (L, 2, &vlen);
                }
@@ -2136,6 +2147,11 @@ lua_task_learn (lua_State *L)
        GError *err = NULL;
        int ret = 1;
 
+       if (task == NULL) {
+               lua_error (L);
+               return 0;
+       }
+
        is_spam = lua_toboolean(L, 2);
        if (lua_gettop (L) > 2) {
                clname = luaL_checkstring (L, 3);
@@ -2162,7 +2178,7 @@ lua_task_set_settings (lua_State *L)
        ucl_object_t *settings;
 
        settings = ucl_object_lua_import (L, 2);
-       if (settings != NULL) {
+       if (settings != NULL && task != NULL) {
                task->settings = settings;
        }
 
@@ -2174,7 +2190,10 @@ lua_task_cache_get (lua_State *L)
 {
        struct rspamd_task *task = lua_check_task (L, 1);
 
-       msg_err_task ("this function is deprecated and will return nothing");
+       if (task) {
+               msg_err_task ("this function is deprecated and will return nothing");
+       }
+
        lua_pushnumber (L, -1);
 
        return 1;
@@ -2185,7 +2204,10 @@ lua_task_cache_set (lua_State *L)
 {
        struct rspamd_task *task = lua_check_task (L, 1);
 
-       msg_err_task ("this function is deprecated and will return nothing");
+       if (task) {
+               msg_err_task ("this function is deprecated and will return nothing");
+       }
+
        lua_pushnumber (L, 0);
 
        return 1;
index 987818608ebb86f805f4be5e04b5cc8dc029e473..8f68d76d1880aa618774bd0512c34fc7d3c867e6 100644 (file)
@@ -176,6 +176,7 @@ lua_trie_search_str (lua_State *L, ac_trie_t *trie, const gchar *str, gsize len,
 {
        struct lua_trie_cbdata cb;
        gboolean icase = FALSE;
+       gint ret;
 
        if (lua_gettop (L) == 4) {
                icase = lua_toboolean (L, 4);
@@ -183,10 +184,13 @@ lua_trie_search_str (lua_State *L, ac_trie_t *trie, const gchar *str, gsize len,
 
        cb.L = L;
        cb.found = FALSE;
-       acism_lookup (trie, str, len,
-                       lua_trie_callback, &cb, statep, icase);
 
-       return cb.found;
+       if ((ret = acism_lookup (trie, str, len,
+                       lua_trie_callback, &cb, statep, icase)) == 0) {
+               return cb.found;
+       }
+
+       return ret;
 }
 
 /***
index d168597d3ee3450c0fa39ceb367ab631fa7bcdf3..be745206f4110609bbecd78caca9c23df8c18459 100644 (file)
@@ -176,7 +176,7 @@ lua_upstream_list_create (lua_State *L)
        guint default_port = 0;
 
        def = luaL_checkstring (L, 2);
-       if (def) {
+       if (def && cfg) {
                if (lua_gettop (L) >= 3) {
                        default_port = luaL_checknumber (L, 3);
                }
@@ -193,6 +193,9 @@ lua_upstream_list_create (lua_State *L)
                        lua_pushnil (L);
                }
        }
+       else {
+               lua_error (L);
+       }
 
        return 1;
 }
index 60456b59fa1cb57bfa7bdd8d2bc91ed0c2de2cbc..6aba9e64f86eada8c34a035dbe609ba0bece76a7 100644 (file)
@@ -290,6 +290,7 @@ lua_accept_socket (gint fd, short what, void *arg)
        }
 
        rspamd_inet_address_destroy (addr);
+       close (nfd);
 }
 
 static gboolean
index e2e18d4e6f2111d6a646dfce8c433ad506c5faa1..5813d1acd7de61ef0867010eb763e2790e19cdb6 100644 (file)
@@ -500,7 +500,7 @@ dkim_module_check (struct dkim_check_result *res)
                }
        }
 
-       if (all_done && res != NULL) {
+       if (all_done) {
                rspamd_session_watcher_pop (res->task->s, res->w);
        }
 }
index 3b2bc54be507907652e9f8adbee9f8319019086a..9edf7fc9def58049c2482d0b533ce1473b69e83a 100644 (file)
@@ -408,10 +408,14 @@ fuzzy_parse_rule (struct rspamd_config *cfg, const ucl_object_t *obj, gint cb_id
 
        if ((value = ucl_object_find_key (obj, "servers")) != NULL) {
                rule->servers = rspamd_upstreams_create (cfg->ups_ctx);
+
                rspamd_mempool_add_destructor (fuzzy_module_ctx->fuzzy_pool,
                                (rspamd_mempool_destruct_t)rspamd_upstreams_destroy,
                                rule->servers);
-               rspamd_upstreams_from_ucl (rule->servers, value, DEFAULT_PORT, NULL);
+               if (!rspamd_upstreams_from_ucl (rule->servers, value, DEFAULT_PORT, NULL)) {
+                       msg_err_config ("cannot read servers definition");
+                       return -1;
+               }
        }
        if ((value = ucl_object_find_key (obj, "fuzzy_map")) != NULL) {
                it = NULL;
@@ -1650,7 +1654,7 @@ fuzzy_controller_timer_callback (gint fd, short what, void *arg)
 
                if (*session->saved > 0 ) {
                        (*session->saved)--;
-                       if (*session->saved == 0 && session->task != NULL) {
+                       if (*session->saved == 0) {
                                rspamd_task_free (session->task);
                                session->task = NULL;
                        }
@@ -2031,7 +2035,7 @@ fuzzy_process_handler (struct rspamd_http_connection_entry *conn_ent,
                                        saved, err);
                }
 
-               if (res) {
+               if (res > 0) {
                        processed = TRUE;
                }
                else if (res == -1) {
index 55a9b97cee4692d013f1164df7db4c5750516053..ca565f3432b5f2eacc953f0fc4c65d6a7891f48e 100644 (file)
@@ -546,10 +546,13 @@ surbl_module_config (struct rspamd_config *cfg)
        if ((value =
                rspamd_config_get_module_opt (cfg, "surbl",
                "redirector_hosts_map")) != NULL) {
-               rspamd_map_add (cfg, ucl_obj_tostring (
-                               value),
+               if (!rspamd_map_add (cfg, ucl_obj_tostring (value),
                        "SURBL redirectors list", read_redirectors_list, fin_redirectors_list,
-                       (void **)&surbl_module_ctx->redirector_map_data);
+                       (void **)&surbl_module_ctx->redirector_map_data)) {
+
+                       msg_warn_config ("bad redirectors map definition: %s",
+                                       ucl_obj_tostring (value));
+               }
        }
 
        if ((value =
index dfe8ac123a7f4b240b2a854fe9f3c22e0cf2b16c..34a5d7aa2f64b683e1ad419703fb9bbfa928964e 100644 (file)
@@ -132,7 +132,7 @@ rspamadm_sign_file (const gchar *fname, const guchar *sk)
                        rspamd_cryptobox_signature_bytes (mode));
 
        rspamd_cryptobox_sign (sig, NULL, map, st.st_size, sk, mode);
-       write (fd_sig, sig, rspamd_cryptobox_signature_bytes (mode));
+       g_assert (write (fd_sig, sig, rspamd_cryptobox_signature_bytes (mode)) != -1);
        close (fd_sig);
        munmap (map, st.st_size);