aboutsummaryrefslogtreecommitdiffstats
path: root/src/libserver
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-02-13 15:57:10 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-02-13 15:57:10 +0000
commit413f74a3577cfe252ed6082f19662d94ffa43549 (patch)
treec372e37485d1e7a03c86061cd792ae899128d8db /src/libserver
parentce060358955a96d65196a9ee431be8d9db87d46e (diff)
downloadrspamd-413f74a3577cfe252ed6082f19662d94ffa43549.tar.gz
rspamd-413f74a3577cfe252ed6082f19662d94ffa43549.zip
[Fix] Fix urls and emails hashes
Diffstat (limited to 'src/libserver')
-rw-r--r--src/libserver/html.c9
-rw-r--r--src/libserver/task.c2
-rw-r--r--src/libserver/url.c25
-rw-r--r--src/libserver/url.h1
4 files changed, 28 insertions, 9 deletions
diff --git a/src/libserver/html.c b/src/libserver/html.c
index 72e8cbd9d..449766a0c 100644
--- a/src/libserver/html.c
+++ b/src/libserver/html.c
@@ -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);
+ }
}
}
}
diff --git a/src/libserver/task.c b/src/libserver/task.c
index 886e1b004..76d9639b3 100644
--- a/src/libserver/task.c
+++ b/src/libserver/task.c
@@ -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);
diff --git a/src/libserver/url.c b/src/libserver/url.c
index c4c5fd038..420c0f959 100644
--- a/src/libserver/url.c
+++ b/src/libserver/url.c
@@ -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;
diff --git a/src/libserver/url.h b/src/libserver/url.h
index 3fab46c5e..7af0bdfb8 100644
--- a/src/libserver/url.h
+++ b/src/libserver/url.h
@@ -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);