]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Try to avoid modifications of the original data
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 30 Mar 2017 13:26:29 +0000 (14:26 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 30 Mar 2017 13:28:13 +0000 (14:28 +0100)
src/libserver/html.c

index b0bea5b8300304ba9c2451d4ae5c8f72041ffa33..31a602e8d5f30a1ce9d20834ede2bc106aedfc9a 100644 (file)
@@ -2111,16 +2111,22 @@ rspamd_html_process_part_full (rspamd_mempool_t *pool, struct html_content *hc,
                                else if (g_ascii_isspace (t)) {
                                        save_space = TRUE;
 
-                                       if (c != p) {
+                                       if (p > c) {
                                                if (need_decode) {
-                                                       len = rspamd_html_decode_entitles_inplace ((gchar *)c,
+                                                       goffset old_offset = dest->len;
+
+                                                       g_byte_array_append (dest, c, (p - c));
+
+                                                       len = rspamd_html_decode_entitles_inplace (
+                                                                       dest->data + old_offset,
                                                                        p - c);
+                                                       dest->len = dest->len + len - (p - c);
                                                }
                                                else {
                                                        len = p - c;
+                                                       g_byte_array_append (dest, c, len);
                                                }
 
-                                               g_byte_array_append (dest, c, len);
                                                if (content_tag) {
                                                        if (content_tag->content == NULL) {
                                                                content_tag->content = c;
@@ -2148,14 +2154,19 @@ rspamd_html_process_part_full (rspamd_mempool_t *pool, struct html_content *hc,
                                if (c != p) {
 
                                        if (need_decode) {
-                                               len = rspamd_html_decode_entitles_inplace ((gchar *)c,
+                                               goffset old_offset = dest->len;
+
+                                               g_byte_array_append (dest, c, (p - c));
+                                               len = rspamd_html_decode_entitles_inplace (
+                                                               dest->data + old_offset,
                                                                p - c);
+                                               dest->len = dest->len + len - (p - c);
                                        }
                                        else {
                                                len = p - c;
+                                               g_byte_array_append (dest, c, len);
                                        }
 
-                                       g_byte_array_append (dest, c, len);
 
                                        if (content_tag) {
                                                if (content_tag->content == NULL) {