diff options
-rw-r--r-- | src/libserver/http/http_router.c | 1 | ||||
-rw-r--r-- | src/libserver/logger/logger.c | 23 | ||||
-rw-r--r-- | src/libserver/milter.c | 8 | ||||
-rw-r--r-- | src/libserver/redis_pool.cxx | 30 | ||||
-rw-r--r-- | src/libserver/rspamd_control.c | 4 | ||||
-rw-r--r-- | src/libserver/rspamd_symcache.c | 8 | ||||
-rw-r--r-- | src/libserver/ssl_util.c | 2 | ||||
-rw-r--r-- | src/libutil/expression.c | 4 | ||||
-rw-r--r-- | src/libutil/fstring.c | 25 | ||||
-rw-r--r-- | src/lua/lua_http.c | 9 | ||||
-rw-r--r-- | src/lua/lua_tcp.c | 4 |
11 files changed, 70 insertions, 48 deletions
diff --git a/src/libserver/http/http_router.c b/src/libserver/http/http_router.c index 960df0ce3..9ff1195ad 100644 --- a/src/libserver/http/http_router.c +++ b/src/libserver/http/http_router.c @@ -199,6 +199,7 @@ rspamd_http_router_try_file (struct rspamd_http_connection_entry *entry, rspamd_http_router_insert_headers (entry->rt, reply_msg); if (!rspamd_http_message_set_body_from_fd (reply_msg, fd)) { + rspamd_http_message_free (reply_msg); close (fd); return FALSE; } diff --git a/src/libserver/logger/logger.c b/src/libserver/logger/logger.c index f65d0fb2e..07625bb91 100644 --- a/src/libserver/logger/logger.c +++ b/src/libserver/logger/logger.c @@ -227,16 +227,21 @@ rspamd_log_open_specific (rspamd_mempool_t *pool, const struct rspamd_logger_funcs *funcs = NULL; - switch (cfg->log_type) { - case RSPAMD_LOG_CONSOLE: + if (cfg) { + switch (cfg->log_type) { + case RSPAMD_LOG_CONSOLE: + funcs = &console_log_funcs; + break; + case RSPAMD_LOG_SYSLOG: + funcs = &syslog_log_funcs; + break; + case RSPAMD_LOG_FILE: + funcs = &file_log_funcs; + break; + } + } + else { funcs = &console_log_funcs; - break; - case RSPAMD_LOG_SYSLOG: - funcs = &syslog_log_funcs; - break; - case RSPAMD_LOG_FILE: - funcs = &file_log_funcs; - break; } g_assert (funcs != NULL); diff --git a/src/libserver/milter.c b/src/libserver/milter.c index 301c26a1f..142f50c92 100644 --- a/src/libserver/milter.c +++ b/src/libserver/milter.c @@ -846,25 +846,25 @@ rspamd_milter_consume_input (struct rspamd_milter_session *session, case st_len_1: /* The first length byte in big endian order */ priv->parser.datalen = 0; - priv->parser.datalen |= *p << 24; + priv->parser.datalen |= ((gsize)*p) << 24; priv->parser.state = st_len_2; p++; break; case st_len_2: /* The second length byte in big endian order */ - priv->parser.datalen |= *p << 16; + priv->parser.datalen |= ((gsize)*p) << 16; priv->parser.state = st_len_3; p++; break; case st_len_3: /* The third length byte in big endian order */ - priv->parser.datalen |= *p << 8; + priv->parser.datalen |= ((gsize)*p) << 8; priv->parser.state = st_len_4; p++; break; case st_len_4: /* The fourth length byte in big endian order */ - priv->parser.datalen |= *p; + priv->parser.datalen |= ((gsize)*p); priv->parser.state = st_read_cmd; p++; break; diff --git a/src/libserver/redis_pool.cxx b/src/libserver/redis_pool.cxx index 46bb81d24..3d56623c8 100644 --- a/src/libserver/redis_pool.cxx +++ b/src/libserver/redis_pool.cxx @@ -51,7 +51,7 @@ class redis_pool; INIT_LOG_MODULE(redis_pool) -enum rspamd_redis_pool_connection_state { +enum class rspamd_redis_pool_connection_state : std::uint8_t { RSPAMD_REDIS_POOL_CONN_INACTIVE = 0, RSPAMD_REDIS_POOL_CONN_ACTIVE, RSPAMD_REDIS_POOL_CONN_FINALISING @@ -65,8 +65,8 @@ struct redis_pool_connection { redis_pool *pool; conn_iter_t elt_pos; ev_timer timeout; - enum rspamd_redis_pool_connection_state state; gchar tag[MEMPOOL_UID_LEN]; + rspamd_redis_pool_connection_state state; auto schedule_timeout() -> void; ~redis_pool_connection(); @@ -125,13 +125,13 @@ public: auto release_connection(const redis_pool_connection *conn) -> void { switch(conn->state) { - case RSPAMD_REDIS_POOL_CONN_ACTIVE: + case rspamd_redis_pool_connection_state::RSPAMD_REDIS_POOL_CONN_ACTIVE: active.erase(conn->elt_pos); break; - case RSPAMD_REDIS_POOL_CONN_INACTIVE: + case rspamd_redis_pool_connection_state::RSPAMD_REDIS_POOL_CONN_INACTIVE: inactive.erase(conn->elt_pos); break; - case RSPAMD_REDIS_POOL_CONN_FINALISING: + case rspamd_redis_pool_connection_state::RSPAMD_REDIS_POOL_CONN_FINALISING: terminating.erase(conn->elt_pos); break; } @@ -260,7 +260,7 @@ redis_pool_connection::~redis_pool_connection() { const auto *conn = this; /* For debug */ - if (state == RSPAMD_REDIS_POOL_CONN_ACTIVE) { + if (state == rspamd_redis_pool_connection_state::RSPAMD_REDIS_POOL_CONN_ACTIVE) { msg_debug_rpool ("active connection destructed: %p", ctx); if (ctx) { @@ -323,12 +323,12 @@ redis_pool_connection::redis_conn_timeout_cb(EV_P_ ev_timer *w, int revents) -> { auto *conn = (struct redis_pool_connection *) w->data; - g_assert (conn->state != RSPAMD_REDIS_POOL_CONN_ACTIVE); + g_assert (conn->state != rspamd_redis_pool_connection_state::RSPAMD_REDIS_POOL_CONN_ACTIVE); - if (conn->state == RSPAMD_REDIS_POOL_CONN_INACTIVE) { + if (conn->state == rspamd_redis_pool_connection_state::RSPAMD_REDIS_POOL_CONN_INACTIVE) { msg_debug_rpool("scheduled soft removal of connection %p", conn->ctx); - conn->state = RSPAMD_REDIS_POOL_CONN_FINALISING; + conn->state = rspamd_redis_pool_connection_state::RSPAMD_REDIS_POOL_CONN_FINALISING; ev_timer_again(EV_A_ w); redisAsyncCommand(conn->ctx, redis_pool_connection::redis_quit_cb, conn, "QUIT"); conn->elt->move_to_terminating(conn); @@ -354,7 +354,7 @@ redis_pool_connection::redis_on_disconnect(const struct redisAsyncContext *ac, i * Here, we know that redis itself will free this connection * so, we need to do something very clever about it */ - if (conn->state != RSPAMD_REDIS_POOL_CONN_ACTIVE) { + if (conn->state != rspamd_redis_pool_connection_state::RSPAMD_REDIS_POOL_CONN_ACTIVE) { /* Do nothing for active connections as it is already handled somewhere */ if (conn->ctx) { msg_debug_rpool("inactive connection terminated: %s", @@ -401,7 +401,7 @@ redis_pool_connection::redis_pool_connection(redis_pool *_pool, : ctx(_ctx), elt(_elt), pool(_pool) { - state = RSPAMD_REDIS_POOL_CONN_ACTIVE; + state = rspamd_redis_pool_connection_state::RSPAMD_REDIS_POOL_CONN_ACTIVE; pool->register_context(ctx, this); ctx->data = this; @@ -429,7 +429,7 @@ redis_pool_elt::new_connection() -> redisAsyncContext * conn.swap(inactive.back()); inactive.pop_back(); - g_assert (conn->state != RSPAMD_REDIS_POOL_CONN_ACTIVE); + g_assert (conn->state != rspamd_redis_pool_connection_state::RSPAMD_REDIS_POOL_CONN_ACTIVE); if (conn->ctx->err == REDIS_OK) { /* Also check SO_ERROR */ gint err; @@ -450,7 +450,7 @@ redis_pool_elt::new_connection() -> redisAsyncContext * else { /* Reuse connection */ ev_timer_stop(pool->event_loop, &conn->timeout); - conn->state = RSPAMD_REDIS_POOL_CONN_ACTIVE; + conn->state = rspamd_redis_pool_connection_state::RSPAMD_REDIS_POOL_CONN_ACTIVE; msg_debug_rpool("reused existing connection to %s:%d: %p", ip.c_str(), port, conn->ctx); active.emplace_front(std::move(conn)); @@ -518,7 +518,7 @@ auto redis_pool::release_connection(redisAsyncContext *ctx, auto conn_it = conns_by_ctx.find(ctx); if (conn_it != conns_by_ctx.end()) { auto *conn = conn_it->second; - g_assert (conn->state == RSPAMD_REDIS_POOL_CONN_ACTIVE); + g_assert (conn->state == rspamd_redis_pool_connection_state::RSPAMD_REDIS_POOL_CONN_ACTIVE); if (ctx->err != REDIS_OK) { /* We need to terminate connection forcefully */ @@ -529,7 +529,7 @@ auto redis_pool::release_connection(redisAsyncContext *ctx, /* Ensure that there are no callbacks attached to this conn */ if (ctx->replies.head == nullptr) { /* Just move it to the inactive queue */ - conn->state = RSPAMD_REDIS_POOL_CONN_INACTIVE; + conn->state = rspamd_redis_pool_connection_state::RSPAMD_REDIS_POOL_CONN_INACTIVE; conn->elt->move_to_inactive(conn); conn->schedule_timeout(); msg_debug_rpool("mark connection %p inactive", conn->ctx); diff --git a/src/libserver/rspamd_control.c b/src/libserver/rspamd_control.c index 0021485c3..b16ddf68f 100644 --- a/src/libserver/rspamd_control.c +++ b/src/libserver/rspamd_control.c @@ -781,7 +781,9 @@ rspamd_control_ignore_io_handler (int fd, short what, void *ud) struct rspamd_control_reply rep; /* At this point we just ignore replies from the workers */ - (void) !read (fd, &rep, sizeof (rep)); + if (read (fd, &rep, sizeof (rep)) == -1) { + msg_debug("cannot read %d bytes: %s", sizeof(rep), strerror(errno)); + } rspamd_control_stop_pending (elt); } diff --git a/src/libserver/rspamd_symcache.c b/src/libserver/rspamd_symcache.c index 41aa784b6..d1fb68672 100644 --- a/src/libserver/rspamd_symcache.c +++ b/src/libserver/rspamd_symcache.c @@ -588,8 +588,10 @@ rspamd_symcache_process_dep (struct rspamd_symcache *cache, vdit = rspamd_symcache_find_filter (cache, dep->sym, false); if (!vdit) { - msg_err_cache ("cannot add dependency from %s on %s: no dependency symbol registered", - dep->sym, dit->symbol); + if (dit) { + msg_err_cache ("cannot add dependency from %s on %s: no dependency symbol registered", + dep->sym, dit->symbol); + } } else { msg_debug_cache ("process virtual dependency %s(%d) on %s(%d)", it->symbol, @@ -698,7 +700,7 @@ rspamd_symcache_post_init (struct rspamd_symcache *cache) vit = rspamd_symcache_find_filter (cache, ddep->from, false); it = rspamd_symcache_find_filter (cache, ddep->from, true); - if (it == NULL) { + if (it == NULL || vit == NULL) { msg_err_cache ("cannot register delayed dependency between %s and %s: " "%s is missing", ddep->from, ddep->to, ddep->from); } diff --git a/src/libserver/ssl_util.c b/src/libserver/ssl_util.c index b9fb175e5..40214ed89 100644 --- a/src/libserver/ssl_util.c +++ b/src/libserver/ssl_util.c @@ -637,7 +637,7 @@ rspamd_ssl_connection_new (gpointer ssl_ctx, struct ev_loop *ev_base, conn->verify_peer = verify_peer; if (log_tag) { - rspamd_strlcpy (conn->log_tag, log_tag, sizeof (log_tag)); + rspamd_strlcpy (conn->log_tag, log_tag, sizeof (conn->log_tag)); } else { rspamd_random_hex (conn->log_tag, sizeof (log_tag) - 1); diff --git a/src/libutil/expression.c b/src/libutil/expression.c index ad78c0fcd..ccbe66195 100644 --- a/src/libutil/expression.c +++ b/src/libutil/expression.c @@ -1183,7 +1183,9 @@ rspamd_parse_expression (const gchar *line, gsize len, return TRUE; error_label: - msg_debug_expression ("fatal error: %e", *err); + if (err && *err) { + msg_debug_expression ("fatal expression parse error: %e", *err); + } while ((tmp = rspamd_expr_stack_elt_pop (operand_stack)) != NULL) { g_node_destroy (tmp); diff --git a/src/libutil/fstring.c b/src/libutil/fstring.c index 652d72d14..3f3af5357 100644 --- a/src/libutil/fstring.c +++ b/src/libutil/fstring.c @@ -272,25 +272,22 @@ rspamd_fstrhash_lc (const rspamd_ftok_t * str, gboolean is_utf) p = str->begin; hval = str->len; + end = p + str->len; if (is_utf) { - while (end < str->begin + str->len) { - if (rspamd_fast_utf8_validate (p, str->len) != 0) { - return rspamd_fstrhash_lc (str, FALSE); - } - while (p < end) { - uc = g_unichar_tolower (g_utf8_get_char (p)); - for (j = 0; j < sizeof (gunichar); j++) { - t = (uc >> (j * 8)) & 0xff; - if (t != 0) { - hval = fstrhash_c (t, hval); - } + if (rspamd_fast_utf8_validate (p, str->len) != 0) { + return rspamd_fstrhash_lc (str, FALSE); + } + while (p < end) { + uc = g_unichar_tolower (g_utf8_get_char (p)); + for (j = 0; j < sizeof (gunichar); j++) { + t = (uc >> (j * 8)) & 0xff; + if (t != 0) { + hval = fstrhash_c (t, hval); } - p = g_utf8_next_char (p); } - p = end + 1; + p = g_utf8_next_char (p); } - } else { for (i = 0; i < str->len; i++, p++) { diff --git a/src/lua/lua_http.c b/src/lua/lua_http.c index 68c9bb927..2f1a1c5a7 100644 --- a/src/lua/lua_http.c +++ b/src/lua/lua_http.c @@ -969,6 +969,9 @@ lua_http_request (lua_State *L) if (body) { rspamd_fstring_free (body); } + if (local_kp) { + rspamd_keypair_unref (local_kp); + } return 1; } @@ -978,6 +981,9 @@ lua_http_request (lua_State *L) if (body) { rspamd_fstring_free (body); } + if (local_kp) { + rspamd_keypair_unref (local_kp); + } return luaL_error (L, "Bad params to rspamd_http:request(): either task or config should be set"); @@ -989,6 +995,9 @@ lua_http_request (lua_State *L) if (body) { rspamd_fstring_free (body); } + if (local_kp) { + rspamd_keypair_unref (local_kp); + } return luaL_error (L, "Bad params to rspamd_http:request(): ev_base isn't passed"); diff --git a/src/lua/lua_tcp.c b/src/lua/lua_tcp.c index a1c1f0b20..f15e25399 100644 --- a/src/lua/lua_tcp.c +++ b/src/lua/lua_tcp.c @@ -1521,6 +1521,8 @@ lua_tcp_request (lua_State *L) event_loop = *(struct ev_loop **)lua_touserdata (L, -1); } else { + g_free (cbd); + return luaL_error (L, "event loop is required"); } lua_pop (L, 1); @@ -1693,6 +1695,8 @@ lua_tcp_request (lua_State *L) if (resolver == NULL && cfg == NULL && task == NULL) { g_free (cbd); + g_free (iov); + return luaL_error (L, "tcp request has bad params: one of " "{resolver,task,config} should be set"); } |