diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-11-25 16:03:27 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-11-25 16:03:27 +0000 |
commit | a69bdc3c0e6f52e1eeef5c2c284da1a3fb250c93 (patch) | |
tree | 41c947f7984836096ebd39c56674ee1989ecc102 /src | |
parent | 2bbcda82057479cf892ff95f30e5b2051bf63ae2 (diff) | |
download | rspamd-a69bdc3c0e6f52e1eeef5c2c284da1a3fb250c93.tar.gz rspamd-a69bdc3c0e6f52e1eeef5c2c284da1a3fb250c93.zip |
[Minor] Add more diagnostic for fuzzy hashes lookup
Diffstat (limited to 'src')
-rw-r--r-- | src/libserver/fuzzy_backend_redis.c | 21 | ||||
-rw-r--r-- | src/plugins/fuzzy_check.c | 43 |
2 files changed, 46 insertions, 18 deletions
diff --git a/src/libserver/fuzzy_backend_redis.c b/src/libserver/fuzzy_backend_redis.c index b77addea4..d9d1cc0a7 100644 --- a/src/libserver/fuzzy_backend_redis.c +++ b/src/libserver/fuzzy_backend_redis.c @@ -86,6 +86,7 @@ struct rspamd_fuzzy_redis_session { gchar **argv; gsize *argv_lens; struct upstream *up; + guchar found_digest[rspamd_cryptobox_HASHBYTES]; }; static inline void @@ -416,10 +417,11 @@ rspamd_fuzzy_redis_shingles_callback (redisAsyncContext *c, gpointer r, session->argv_lens[2] = 1; session->argv[3] = g_strdup ("F"); session->argv_lens[3] = 1; - session->argv[3] = g_strdup ("C"); - session->argv_lens[3] = 1; + session->argv[4] = g_strdup ("C"); + session->argv_lens[4] = 1; g_string_free (key, FALSE); /* Do not free underlying array */ - memcpy (rep.digest, sel->digest, sizeof (rep.digest)); + memcpy (session->found_digest, sel->digest, + sizeof (session->cmd->digest)); g_assert (session->ctx != NULL); if (redisAsyncCommandArgv (session->ctx, @@ -476,7 +478,7 @@ rspamd_fuzzy_backend_check_shingles (struct rspamd_fuzzy_redis_session *session) struct rspamd_fuzzy_reply rep; const struct rspamd_fuzzy_shingle_cmd *shcmd; GString *key; - guint i; + guint i, init_len; rspamd_fuzzy_redis_session_free_args (session); /* First of all check digest */ @@ -487,10 +489,13 @@ rspamd_fuzzy_backend_check_shingles (struct rspamd_fuzzy_redis_session *session) session->argv[0] = g_strdup ("MGET"); session->argv_lens[0] = 4; + init_len = strlen (session->backend->redis_object); for (i = 0; i < RSPAMD_SHINGLE_SIZE; i ++) { - key = g_string_new (session->backend->redis_object); - rspamd_printf_gstring (key, "_%d_%uL", i, shcmd->sgl.hashes[i]); + + key = g_string_sized_new (init_len + 2 + 2 + sizeof ("18446744073709551616")); + rspamd_printf_gstring (key, "%s_%d_%uL", session->backend->redis_object, + i, shcmd->sgl.hashes[i]); session->argv[i + 1] = key->str; session->argv_lens[i + 1] = key->len; g_string_free (key, FALSE); /* Do not free underlying array */ @@ -557,7 +562,7 @@ rspamd_fuzzy_redis_check_callback (redisAsyncContext *c, gpointer r, if (found_elts >= 2) { rep.v1.prob = session->prob; - memcpy (rep.digest, session->cmd->digest, sizeof (rep.digest)); + memcpy (rep.digest, session->found_digest, sizeof (rep.digest)); } rep.ts = 0; @@ -630,6 +635,8 @@ rspamd_fuzzy_backend_check_redis (struct rspamd_fuzzy_backend *bk, session->command = RSPAMD_FUZZY_REDIS_COMMAND_CHECK; session->cmd = cmd; session->prob = 1.0; + memcpy (rep.digest, session->cmd->digest, sizeof (rep.digest)); + memcpy (session->found_digest, session->cmd->digest, sizeof (rep.digest)); session->ev_base = rspamd_fuzzy_backend_event_base (bk); /* First of all check digest */ diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c index c504e7603..0a3d3803a 100644 --- a/src/plugins/fuzzy_check.c +++ b/src/plugins/fuzzy_check.c @@ -1804,6 +1804,7 @@ fuzzy_insert_result (struct fuzzy_client_session *session, guchar buf[2048]; const gchar *type = "bin"; struct fuzzy_client_result *res; + gboolean is_fuzzy = FALSE; /* Get mapping by flag */ if ((map = @@ -1848,23 +1849,43 @@ fuzzy_insert_result (struct fuzzy_client_session *session, } res->score = nval; - msg_info_task ( - "found fuzzy hash(%s) %*xs with weight: " - "%.2f, probability %.2f, in list: %s:%d%s", - type, - (gint)sizeof (rep->digest), rep->digest, - nval, - (gdouble)rep->v1.prob, - symbol, - rep->v1.flag, - map == NULL ? "(unknown)" : ""); + + if (memcmp (rep->digest, cmd->digest, sizeof (rep->digest)) != 0) { + is_fuzzy = TRUE; + } + + if (is_fuzzy) { + msg_info_task ( + "found fuzzy hash(%s) %*xs (%*xs requested) with weight: " + "%.2f, probability %.2f, in list: %s:%d%s", + type, + (gint) sizeof (rep->digest), rep->digest, + (gint) sizeof (cmd->digest), cmd->digest, + nval, + (gdouble) rep->v1.prob, + symbol, + rep->v1.flag, + map == NULL ? "(unknown)" : ""); + } + else { + msg_info_task ( + "found exact fuzzy hash(%s) %*xs with weight: " + "%.2f, probability %.2f, in list: %s:%d%s", + type, + (gint) sizeof (rep->digest), rep->digest, + nval, + (gdouble) rep->v1.prob, + symbol, + rep->v1.flag, + map == NULL ? "(unknown)" : ""); + } if (map != NULL || !session->rule->skip_unknown) { rspamd_snprintf (buf, sizeof (buf), "%d:%*xs:%.2f:%s", rep->v1.flag, - (gint)sizeof (rep->digest), rep->digest, + (gint)MIN(rspamd_fuzzy_hash_len, sizeof (rep->digest)), rep->digest, rep->v1.prob, type); res->option = rspamd_mempool_strdup (task->task_pool, buf); |