]> granicus.if.org Git - neomutt/commitdiff
Make a copy of x_label before encoding it for updates
authorKevin McCarthy <kevin@8t8.us>
Fri, 28 Dec 2018 23:43:51 +0000 (15:43 -0800)
committerRichard Russon <rich@flatcap.org>
Mon, 7 Jan 2019 15:09:41 +0000 (15:09 +0000)
This isn't actually a bug.  Context->label_hash strdups the keys, so
we are safe from dangling references.  However, the subj_hash uses
direct references, so to keep things consistent and safe, make a copy
and encode that.

Co-authored-by: Richard Russon <rich@flatcap.org>
copy.c

diff --git a/copy.c b/copy.c
index c9b0d248dfc987ff897df031ba975b86711bb267..e32b929fd1e5141f3e1f8f729ab990a9f0a496bd 100644 (file)
--- a/copy.c
+++ b/copy.c
@@ -405,6 +405,8 @@ int mutt_copy_hdr(FILE *in, FILE *out, LOFF_T off_start, LOFF_T off_end,
  */
 int mutt_copy_header(FILE *in, struct Email *e, FILE *out, int flags, const char *prefix)
 {
+  char *temp_hdr = NULL;
+
   if (e->env)
   {
     flags |= (e->env->irt_changed ? CH_UPDATE_IRT : 0) |
@@ -505,15 +507,21 @@ int mutt_copy_header(FILE *in, struct Email *e, FILE *out, int flags, const char
   if ((flags & CH_UPDATE_LABEL) && e->env->x_label)
   {
     e->xlabel_changed = 0;
+    temp_hdr = e->env->x_label;
+    /* env->x_label isn't currently stored with direct references elsewhere.
+     * Context->label_hash strdups the keys.  But to be safe, encode a copy */
     if (!(flags & CH_DECODE))
-      rfc2047_encode(&e->env->x_label, NULL, sizeof("X-Label:"), SendCharset);
-    if (mutt_write_one_header(out, "X-Label", e->env->x_label, flags & CH_PREFIX ? prefix : 0,
+    {
+      temp_hdr = mutt_str_strdup(temp_hdr);
+      rfc2047_encode(&temp_hdr, NULL, sizeof("X-Label:"), SendCharset);
+    }
+    if (mutt_write_one_header(out, "X-Label", temp_hdr, flags & CH_PREFIX ? prefix : 0,
                               mutt_window_wrap_cols(MuttIndexWindow, Wrap), flags) == -1)
     {
       return -1;
     }
     if (!(flags & CH_DECODE))
-      rfc2047_decode(&e->env->x_label);
+      FREE(&temp_hdr);
   }
 
   if ((flags & CH_NONEWLINE) == 0)