gchar **argv;
gsize *argv_lens;
struct upstream *up;
+ guchar found_digest[rspamd_cryptobox_HASHBYTES];
};
static inline void
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,
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 */
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 */
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;
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 */
guchar buf[2048];
const gchar *type = "bin";
struct fuzzy_client_result *res;
+ gboolean is_fuzzy = FALSE;
/* Get mapping by flag */
if ((map =
}
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);