]> source.dussan.org Git - rspamd.git/commitdiff
Fix errors processing in fuzzy check
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 15 Dec 2015 21:55:34 +0000 (21:55 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 15 Dec 2015 21:55:34 +0000 (21:55 +0000)
src/fuzzy_storage.c
src/libserver/fuzzy_backend.c
src/plugins/fuzzy_check.c

index dcf538b0dbab4e785176eedf60d22e5e1be66a7e..34b5e631f2bc22c8274b24c995434fac96152ae2 100644 (file)
@@ -322,7 +322,7 @@ rspamd_fuzzy_update_stats (enum rspamd_fuzzy_epoch epoch, gboolean matched,
 #endif
 
        if (key_stat) {
-               if (reply != 0) {
+               if (!matched && reply != 0) {
                        key_stat->errors ++;
                }
                else {
@@ -343,7 +343,7 @@ rspamd_fuzzy_update_stats (enum rspamd_fuzzy_epoch epoch, gboolean matched,
        }
 
        if (ip_stat) {
-               if (reply != 0) {
+               if (!matched && reply != 0) {
                        ip_stat->errors++;
                }
                else {
index d525a9c56db04639cc7889316093f8e456462a38..4a59e367c07e1a8c27fc14250bfabfbe1c44868d 100644 (file)
@@ -544,25 +544,39 @@ rspamd_fuzzy_backend_check (struct rspamd_fuzzy_backend *backend,
                if (sel_id != -1) {
                        /* We have some id selected here */
                        rep.prob = (float)max_cnt / (float)RSPAMD_SHINGLE_SIZE;
-                       msg_debug_fuzzy_backend ("found fuzzy hash with probability %.2f", rep.prob);
-                       rc = rspamd_fuzzy_backend_run_stmt (backend, FALSE,
-                                       RSPAMD_FUZZY_BACKEND_GET_DIGEST_BY_ID, sel_id);
-                       if (rc == SQLITE_OK) {
-                               digest = sqlite3_column_text (
-                                               prepared_stmts[RSPAMD_FUZZY_BACKEND_GET_DIGEST_BY_ID].stmt, 0);
-                               timestamp = sqlite3_column_int64 (
-                                               prepared_stmts[RSPAMD_FUZZY_BACKEND_GET_DIGEST_BY_ID].stmt, 2);
-                               if (time (NULL) - timestamp > expire) {
-                                       /* Expire element */
-                                       msg_debug_fuzzy_backend ("requested hash has been expired");
-                               }
-                               else {
-                                       rep.value = sqlite3_column_int64 (
-                                                       prepared_stmts[RSPAMD_FUZZY_BACKEND_GET_DIGEST_BY_ID].stmt, 1);
-                                       rep.flag = sqlite3_column_int (
-                                                       prepared_stmts[RSPAMD_FUZZY_BACKEND_GET_DIGEST_BY_ID].stmt, 3);
+
+                       if (rep.prob > 0.5) {
+                               msg_debug_fuzzy_backend (
+                                               "found fuzzy hash with probability %.2f",
+                                               rep.prob);
+                               rc = rspamd_fuzzy_backend_run_stmt (backend, FALSE,
+                                               RSPAMD_FUZZY_BACKEND_GET_DIGEST_BY_ID, sel_id);
+                               if (rc == SQLITE_OK) {
+                                       digest = sqlite3_column_text (
+                                                       prepared_stmts[RSPAMD_FUZZY_BACKEND_GET_DIGEST_BY_ID].stmt,
+                                                       0);
+                                       timestamp = sqlite3_column_int64 (
+                                                       prepared_stmts[RSPAMD_FUZZY_BACKEND_GET_DIGEST_BY_ID].stmt,
+                                                       2);
+                                       if (time (NULL) - timestamp > expire) {
+                                               /* Expire element */
+                                               msg_debug_fuzzy_backend (
+                                                               "requested hash has been expired");
+                                       }
+                                       else {
+                                               rep.value = sqlite3_column_int64 (
+                                                               prepared_stmts[RSPAMD_FUZZY_BACKEND_GET_DIGEST_BY_ID].stmt,
+                                                               1);
+                                               rep.flag = sqlite3_column_int (
+                                                               prepared_stmts[RSPAMD_FUZZY_BACKEND_GET_DIGEST_BY_ID].stmt,
+                                                               3);
+                                       }
                                }
                        }
+                       else {
+                               /* Otherwise we assume that as error */
+                               rep.value = 0;
+                       }
 
                        rspamd_fuzzy_backend_cleanup_stmt (backend,
                                        RSPAMD_FUZZY_BACKEND_GET_DIGEST_BY_ID);
index 8181bf379c1609f975c847756fd2df65e64af6d1..cdc4ef508e77bb0a7526634f53010b9ea1a90cc6 100644 (file)
@@ -1112,33 +1112,37 @@ fuzzy_check_io_callback (gint fd, short what, void *arg)
                                        symbol = map->symbol;
                                }
 
-                               if (rep->value == 0) {
-                                       if (rep->prob > 0.5) {
-                                               nval = fuzzy_normalize (rep->value,
-                                                               session->rule->max_score);
-                                               nval *= rep->prob;
-                                               msg_info_task (
-                                                               "found fuzzy hash with weight: "
-                                                               "%.2f, in list: %s:%d%s",
-                                                               nval,
-                                                               symbol,
+
+                               /*
+                                * Hash is assumed to be found if probability is more than 0.5
+                                * In that case `value` means number of matches
+                                * Otherwise `value` means error code
+                                */
+                               if (rep->prob > 0.5) {
+                                       nval = fuzzy_normalize (rep->value,
+                                                       session->rule->max_score);
+                                       nval *= rep->prob;
+                                       msg_info_task (
+                                                       "found fuzzy hash with weight: "
+                                                                       "%.2f, in list: %s:%d%s",
+                                                       nval,
+                                                       symbol,
+                                                       rep->flag,
+                                                       map == NULL ? "(unknown)" : "");
+                                       if (map != NULL || !session->rule->skip_unknown) {
+                                               rspamd_snprintf (buf,
+                                                               sizeof (buf),
+                                                               "%d: %.2f / %.2f",
                                                                rep->flag,
-                                                               map == NULL ? "(unknown)" : "");
-                                               if (map != NULL || !session->rule->skip_unknown) {
-                                                       rspamd_snprintf (buf,
-                                                                       sizeof (buf),
-                                                                       "%d: %.2f / %.2f",
-                                                                       rep->flag,
-                                                                       rep->prob,
-                                                                       nval);
-                                                       rspamd_task_insert_result_single (session->task,
-                                                                       symbol,
-                                                                       nval,
-                                                                       g_list_prepend (NULL,
-                                                                                       rspamd_mempool_strdup (
-                                                                                                       session->task->task_pool,
-                                                                                                       buf)));
-                                               }
+                                                               rep->prob,
+                                                               nval);
+                                               rspamd_task_insert_result_single (session->task,
+                                                               symbol,
+                                                               nval,
+                                                               g_list_prepend (NULL,
+                                                                               rspamd_mempool_strdup (
+                                                                                               session->task->task_pool,
+                                                                                               buf)));
                                        }
                                }
                                else if (rep->value == 403) {