]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Fix] More fixes in html tag content calculations
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 9 Jan 2020 15:00:54 +0000 (15:00 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 9 Jan 2020 15:00:54 +0000 (15:00 +0000)
src/libserver/html.c
src/lua/lua_html.c

index 502fa42faa51979c52f205692df0dff2a72a3f45..a6b03786158ac3cdbb197fccb05809e71f6c57ba 100644 (file)
@@ -2790,7 +2790,7 @@ rspamd_html_process_part_full (rspamd_mempool_t *pool, struct html_content *hc,
                                                        goffset old_offset = dest->len;
 
                                                        if (content_tag) {
-                                                               if (content_tag->content_offset == 0) {
+                                                               if (content_tag->content_length == 0) {
                                                                        content_tag->content_offset = old_offset;
                                                                }
                                                        }
@@ -2810,7 +2810,7 @@ rspamd_html_process_part_full (rspamd_mempool_t *pool, struct html_content *hc,
                                                        len = p - c;
 
                                                        if (content_tag) {
-                                                               if (content_tag->content_offset == 0) {
+                                                               if (content_tag->content_length == 0) {
                                                                        content_tag->content_offset = dest->len;
                                                                }
 
@@ -2831,7 +2831,18 @@ rspamd_html_process_part_full (rspamd_mempool_t *pool, struct html_content *hc,
                                                                !g_ascii_isspace (dest->data[dest->len - 1])) {
                                                        g_byte_array_append (dest, " ", 1);
                                                        if (content_tag) {
-                                                               content_tag->content_length ++;
+                                                               if (content_tag->content_length == 0) {
+                                                                       /*
+                                                                        * Special case
+                                                                        * we have a space at the beginning but
+                                                                        * we have no set content_offset
+                                                                        * so we need to do it here
+                                                                        */
+                                                                       content_tag->content_offset = dest->len;
+                                                               }
+                                                               else {
+                                                                       content_tag->content_length++;
+                                                               }
                                                        }
                                                }
                                                save_space = FALSE;
@@ -2845,7 +2856,7 @@ rspamd_html_process_part_full (rspamd_mempool_t *pool, struct html_content *hc,
                                                goffset old_offset = dest->len;
 
                                                if (content_tag) {
-                                                       if (content_tag->content_offset == 0) {
+                                                       if (content_tag->content_length == 0) {
                                                                content_tag->content_offset = dest->len;
                                                        }
                                                }
@@ -2864,7 +2875,7 @@ rspamd_html_process_part_full (rspamd_mempool_t *pool, struct html_content *hc,
                                                len = p - c;
 
                                                if (content_tag) {
-                                                       if (content_tag->content_offset == 0) {
+                                                       if (content_tag->content_length == 0) {
                                                                content_tag->content_offset = dest->len;
                                                        }
 
@@ -2962,7 +2973,18 @@ rspamd_html_process_part_full (rspamd_mempool_t *pool, struct html_content *hc,
                                                g_byte_array_append (dest, "\r\n", 2);
 
                                                if (content_tag) {
-                                                       content_tag->content_length += 2;
+                                                       if (content_tag->content_length == 0) {
+                                                               /*
+                                                                * Special case
+                                                                * we have a \r\n at the beginning but
+                                                                * we have no set content_offset
+                                                                * so we need to do it here
+                                                                */
+                                                               content_tag->content_offset = dest->len;
+                                                       }
+                                                       else {
+                                                               content_tag->content_length += 2;
+                                                       }
                                                }
                                        }
                                        save_space = FALSE;
@@ -2975,7 +2997,18 @@ rspamd_html_process_part_full (rspamd_mempool_t *pool, struct html_content *hc,
                                                g_byte_array_append (dest, "\r\n", 2);
 
                                                if (content_tag) {
-                                                       content_tag->content_length += 2;
+                                                       if (content_tag->content_length == 0) {
+                                                               /*
+                                                                * Special case
+                                                                * we have a \r\n at the beginning but
+                                                                * we have no set content_offset
+                                                                * so we need to get it here
+                                                                */
+                                                               content_tag->content_offset = dest->len;
+                                                       }
+                                                       else {
+                                                               content_tag->content_length += 2;
+                                                       }
                                                }
                                        }
                                        save_space = FALSE;
index 43c34797cfd6fe451c12409237a61eadca870395..c0e07de36d7445c4a93428ad1ee8d97dfb108957 100644 (file)
@@ -663,7 +663,7 @@ lua_html_tag_get_content (lua_State *L)
        struct rspamd_lua_text *t;
 
        if (ltag) {
-               if (ltag->html && ltag->tag->content_offset && ltag->tag->content_length &&
+               if (ltag->html && ltag->tag->content_length &&
                                ltag->html->parsed->len >= ltag->tag->content_offset + ltag->tag->content_length) {
                        t = lua_newuserdata (L, sizeof (*t));
                        rspamd_lua_setclass (L, "rspamd{text}", -1);