]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Fix rewrite subject
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 20 Dec 2016 17:11:34 +0000 (17:11 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 20 Dec 2016 17:14:18 +0000 (17:14 +0000)
src/libserver/protocol.c

index cc88cfd0c90f60764a6d37d61ab86eb9485f21bb..8b7c4b6f699512d26b2fb8d8e5dc99ebff9092af 100644 (file)
@@ -768,38 +768,51 @@ rspamd_emails_tree_ucl (GHashTable *input, struct rspamd_task *task)
 static const gchar *
 make_rewritten_subject (struct rspamd_metric *metric, struct rspamd_task *task)
 {
-       static gchar subj_buf[1024];
-       gchar *p = subj_buf, *end, *res;
-       const gchar *s, *c;
+       GString *subj_buf;
+       gchar *res;
+       const gchar *s, *c, *p;
+       gsize slen = 0;
 
-       end = p + sizeof(subj_buf);
        c = metric->subject;
+
        if (c == NULL) {
                c = SPAM_SUBJECT;
        }
 
+       p = c;
        s = task->subject;
 
-       while (p < end) {
-               if (*c == '\0') {
-                       *p = '\0';
-                       break;
-               }
-               else if (*c == '%' && *(c + 1) == 's') {
-                       p += rspamd_strlcpy (p, (s != NULL) ? s : "", end - p);
-                       c += 2;
-               }
-               else {
-                       *p = *c++;
+       if (s) {
+               slen = strlen (s);
+       }
+
+       subj_buf = g_string_sized_new (strlen (c) + slen);
+
+       while (*p) {
+               if (*p == '%' && *(p + 1) == 's') {
+                       g_string_append_len (subj_buf, c, p - c);
+
+                       if (s) {
+                               g_string_append_len (subj_buf, s, slen);
+                       }
+
+                       p += 2;
+                       c = p;
                }
-               p++;
+
+               p ++;
+       }
+
+       if (p > c) {
+               g_string_append_len (subj_buf, c, p - c);
        }
 
-       res = rspamd_mime_header_encode (subj_buf, strlen (subj_buf));
+       res = rspamd_mime_header_encode (subj_buf->str, subj_buf->len);
 
        rspamd_mempool_add_destructor (task->task_pool,
                (rspamd_mempool_destruct_t)g_free,
                res);
+       g_string_free (subj_buf, TRUE);
 
        return res;
 }