]> source.dussan.org Git - rspamd.git/commitdiff
Make phishing checks working.
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Sat, 5 Mar 2011 15:55:44 +0000 (18:55 +0300)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Sat, 5 Mar 2011 15:55:44 +0000 (18:55 +0300)
src/html.c
src/html.h
src/message.c
src/plugins/lua/multimap.lua

index 2ab441ad3b649ed260a10b1c1560fb011ee1e485..e99403a8ac6abd53c74d18db81d7b24416e7b6c4 100644 (file)
@@ -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) {
index 0758183925ea9af3e4836df55bb5b5bb179132d9..e447fd3d0022f2c02c0fd246aad4fdef3efd80e6 100644 (file)
@@ -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);
 
index 78094b32b48260a75ac19a6af819401031df1634..b4ddde83940fdf63474fa807d18943d2c4608a4d 100644 (file)
@@ -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 */
index 15c90665732a0d29542ddb9e36ce069209927bb3..a4ef3c0a5e1e2e0fdbb2a5eef9a511bbb41bb753 100644 (file)
@@ -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