diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2011-03-05 18:55:44 +0300 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2011-03-05 18:55:44 +0300 |
commit | 7487d02f1b3224a913e66d9940adcdaf9c966e7d (patch) | |
tree | 9a938f35588568fe5aa049df96e0a8bf37530712 | |
parent | c494636eedee963c4789fc7b8a0cd7d9acc80e18 (diff) | |
download | rspamd-7487d02f1b3224a913e66d9940adcdaf9c966e7d.tar.gz rspamd-7487d02f1b3224a913e66d9940adcdaf9c966e7d.zip |
Make phishing checks working.
-rw-r--r-- | src/html.c | 13 | ||||
-rw-r--r-- | src/html.h | 2 | ||||
-rw-r--r-- | src/message.c | 5 | ||||
-rw-r--r-- | src/plugins/lua/multimap.lua | 13 |
4 files changed, 23 insertions, 10 deletions
diff --git a/src/html.c b/src/html.c index 2ab441ad3..e99403a8a 100644 --- a/src/html.c +++ b/src/html.c @@ -688,7 +688,7 @@ check_phishing (struct worker_task *task, struct uri *href_url, const gchar *url gint off, rc; p = url_text; - while (len < remain) { + while (len < remain - 1) { if (*p == '<' || *p == '>') { break; } @@ -717,7 +717,8 @@ check_phishing (struct worker_task *task, struct uri *href_url, const gchar *url } static void -parse_tag_url (struct worker_task *task, struct mime_text_part *part, tag_id_t id, gchar *tag_text, gsize tag_len) +parse_tag_url (struct worker_task *task, struct mime_text_part *part, tag_id_t id, + gchar *tag_text, gsize tag_len, gsize remain) { gchar *c = NULL, *p, *url_text; gint len, rc; @@ -804,7 +805,7 @@ parse_tag_url (struct worker_task *task, struct mime_text_part *part, tag_id_t i * Check for phishing */ if ((p = strchr (c, '>')) != NULL ) { - check_phishing (task, url, p + 1, tag_len - (p - tag_text)); + check_phishing (task, url, p + 1, remain - (p - tag_text)); } if (part->html_urls && g_tree_lookup (part->html_urls, url_text) == NULL) { g_tree_insert (part->html_urls, url_text, url); @@ -818,7 +819,7 @@ parse_tag_url (struct worker_task *task, struct mime_text_part *part, tag_id_t i gboolean add_html_node (struct worker_task *task, memory_pool_t * pool, struct mime_text_part *part, - gchar *tag_text, gsize tag_len, GNode ** cur_level) + gchar *tag_text, gsize tag_len, gsize remain, GNode ** cur_level) { GNode *new; struct html_node *data; @@ -843,7 +844,7 @@ add_html_node (struct worker_task *task, memory_pool_t * pool, struct mime_text_ part->html_nodes = new; memory_pool_add_destructor (pool, (pool_destruct_func) g_node_destroy, part->html_nodes); /* Call once again with root node */ - return add_html_node (task, pool, part, tag_text, tag_len, cur_level); + return add_html_node (task, pool, part, tag_text, tag_len, remain, cur_level); } else { new = construct_html_node (pool, tag_text, tag_len); @@ -853,7 +854,7 @@ add_html_node (struct worker_task *task, memory_pool_t * pool, struct mime_text_ } data = new->data; if (data->tag && (data->tag->id == Tag_A || data->tag->id == Tag_IMG) && ((data->flags & FL_CLOSING) == 0)) { - parse_tag_url (task, part, data->tag->id, tag_text, tag_len); + parse_tag_url (task, part, data->tag->id, tag_text, tag_len, remain); } if (data->flags & FL_CLOSING) { diff --git a/src/html.h b/src/html.h index 075818392..e447fd3d0 100644 --- a/src/html.h +++ b/src/html.h @@ -208,7 +208,7 @@ struct html_node { struct worker_task; gboolean add_html_node (struct worker_task *task, memory_pool_t *pool, - struct mime_text_part *part, gchar *tag_text, gsize tag_len, GNode **cur_level); + struct mime_text_part *part, gchar *tag_text, gsize tag_len, gsize remain, GNode **cur_level); struct html_tag * get_tag_by_name (const gchar *name); void decode_entitles (gchar *s, guint *len); diff --git a/src/message.c b/src/message.c index 78094b32b..b4ddde839 100644 --- a/src/message.c +++ b/src/message.c @@ -37,7 +37,7 @@ GByteArray * strip_html_tags (struct worker_task *task, memory_pool_t * pool, struct mime_text_part *part, GByteArray * src, gint *stateptr) { - uint8_t *tbuf = NULL, *p, *tp = NULL, *rp, *tbegin = NULL, c, lc; + uint8_t *tbuf = NULL, *p, *tp = NULL, *rp, *tbegin = NULL, *end, c, lc; gint br, i = 0, depth = 0, in_q = 0; gint state = 0; GByteArray *buf; @@ -54,6 +54,7 @@ strip_html_tags (struct worker_task *task, memory_pool_t * pool, struct mime_tex lc = '\0'; p = src->data; rp = buf->data; + end = src->data + src->len; br = 0; while (i < src->len) { @@ -112,7 +113,7 @@ strip_html_tags (struct worker_task *task, memory_pool_t * pool, struct mime_tex case 1: /* HTML/XML */ lc = '>'; in_q = state = 0; - erase = !add_html_node (task, pool, part, tbegin, p - tbegin, &level_ptr); + erase = !add_html_node (task, pool, part, tbegin, p - tbegin, end - tbegin, &level_ptr); break; case 2: /* PHP */ diff --git a/src/plugins/lua/multimap.lua b/src/plugins/lua/multimap.lua index 15c906657..a4ef3c0a5 100644 --- a/src/plugins/lua/multimap.lua +++ b/src/plugins/lua/multimap.lua @@ -214,10 +214,21 @@ local function add_multimap_rule(params) end if newrule['type'] == 'ip' then newrule['ips'] = rspamd_config:add_radix_map (newrule['map']) + if newrule['ips'] then + table.insert(rules, newrule) + else + rspamd_logger.warn('Cannot add rule: map doesn\'t exists: ' .. newrule['map']) + end elseif newrule['type'] == 'header' or newrule['type'] == 'rcpt' or newrule['type'] == 'from' then newrule['hash'] = rspamd_config:add_hash_map (newrule['map']) + if newrule['hash'] then + table.insert(rules, newrule) + else + rspamd_logger.warn('Cannot add rule: map doesn\'t exists: ' .. newrule['map']) + end + else + table.insert(rules, newrule) end - table.insert(rules, newrule) return newrule end |