]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Fix urls and emails hashes
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 13 Feb 2017 15:57:10 +0000 (15:57 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 13 Feb 2017 15:57:10 +0000 (15:57 +0000)
src/libserver/html.c
src/libserver/task.c
src/libserver/url.c
src/libserver/url.h

index 72e8cbd9d2713b49d2de96df2b6cac21003bf678..449766a0cd935aa391e22fb28a8d1a3028b5a80c 100644 (file)
@@ -2150,7 +2150,7 @@ rspamd_html_process_part_full (rspamd_mempool_t *pool, struct html_content *hc,
                                                        }
 
                                                        if (displayed_url) {
-                                                               if (url->protocol == PROTOCOL_MAILTO) {
+                                                               if (displayed_url->protocol == PROTOCOL_MAILTO) {
                                                                        target_tbl = emails;
                                                                }
                                                                else {
@@ -2158,7 +2158,8 @@ rspamd_html_process_part_full (rspamd_mempool_t *pool, struct html_content *hc,
                                                                }
 
                                                                if (target_tbl != NULL) {
-                                                                       turl = g_hash_table_lookup (target_tbl, url);
+                                                                       turl = g_hash_table_lookup (target_tbl,
+                                                                                       displayed_url);
 
                                                                        if (turl != NULL) {
                                                                                /* Here, we assume the following:
@@ -2172,6 +2173,10 @@ rspamd_html_process_part_full (rspamd_mempool_t *pool, struct html_content *hc,
                                                                                        turl->flags &= ~RSPAMD_URL_FLAG_FROM_TEXT;
                                                                                }
                                                                        }
+                                                                       else {
+                                                                               g_hash_table_insert (target_tbl,
+                                                                                               displayed_url, displayed_url);
+                                                                       }
                                                                }
                                                        }
                                                }
index 886e1b0040399bbcc8a93577811dd33676ea8570..76d9639b3652c1a61d554da4b1a5f94ca67baf74 100644 (file)
@@ -105,7 +105,7 @@ rspamd_task_new (struct rspamd_worker *worker, struct rspamd_config *cfg)
        rspamd_mempool_add_destructor (new_task->task_pool,
                (rspamd_mempool_destruct_t) g_hash_table_unref,
                new_task->raw_headers);
-       new_task->emails = g_hash_table_new (rspamd_url_hash, rspamd_emails_cmp);
+       new_task->emails = g_hash_table_new (rspamd_email_hash, rspamd_emails_cmp);
        rspamd_mempool_add_destructor (new_task->task_pool,
                (rspamd_mempool_destruct_t) g_hash_table_unref,
                new_task->emails);
index c4c5fd038456acee1640c21b7171a1d98f1d30a6..420c0f95951c4be57c34002ed2749c9319d12272 100644 (file)
@@ -2584,7 +2584,24 @@ rspamd_url_hash (gconstpointer u)
                rspamd_cryptobox_fast_hash_update (&st, url->string, url->urllen);
        }
 
-       rspamd_cryptobox_fast_hash_update (&st, &url->flags, sizeof (url->flags));
+       return rspamd_cryptobox_fast_hash_final (&st);
+}
+
+guint
+rspamd_email_hash (gconstpointer u)
+{
+       const struct rspamd_url *url = u;
+       rspamd_cryptobox_fast_hash_state_t st;
+
+       rspamd_cryptobox_fast_hash_init (&st, rspamd_hash_seed ());
+
+       if (url->hostlen > 0) {
+               rspamd_cryptobox_fast_hash_update (&st, url->host, url->hostlen);
+       }
+
+       if (url->userlen > 0) {
+               rspamd_cryptobox_fast_hash_update (&st, url->user, url->userlen);
+       }
 
        return rspamd_cryptobox_fast_hash_final (&st);
 }
@@ -2621,17 +2638,13 @@ gboolean
 rspamd_urls_cmp (gconstpointer a, gconstpointer b)
 {
        const struct rspamd_url *u1 = a, *u2 = b;
-       int r;
+       int r = 0;
 
        if (u1->urllen != u2->urllen) {
                return FALSE;
        }
        else {
                r = memcmp (u1->string, u2->string, u1->urllen);
-               if (r == 0 && u1->flags != u2->flags) {
-                       /* Always insert phished urls to the tree */
-                       return FALSE;
-               }
        }
 
        return r == 0;
index 3fab46c5ea5145d6000d7619cf2db41b74708d02..7af0bdfb8dcf249dcaef8be975bd0851851e83bf 100644 (file)
@@ -180,6 +180,7 @@ void rspamd_url_add_tag (struct rspamd_url *url, const gchar *tag,
                rspamd_mempool_t *pool);
 
 guint rspamd_url_hash (gconstpointer u);
+guint rspamd_email_hash (gconstpointer u);
 
 /* Compare two emails for building emails hash */
 gboolean rspamd_emails_cmp (gconstpointer a, gconstpointer b);