]> granicus.if.org Git - neomutt/commitdiff
Fix segfault when viewing text attachments in compose menu. (closes #3644)
authorKevin McCarthy <kevin@8t8.us>
Sat, 5 Oct 2013 07:57:49 +0000 (15:57 +0800)
committerKevin McCarthy <kevin@8t8.us>
Sat, 5 Oct 2013 07:57:49 +0000 (15:57 +0800)
The segfault was introduced in changeset b9f9e3147eb4.  Since decoding
and charset conversion aren't needed for attachments when composing a
message, this patch reverts to just using mutt_save_attachment() to view
"raw data" for text attachments in the compose/send case.

This patch is based on Michael Elkins' patch at
http://dev.mutt.org/trac/attachment/ticket/3644/view_attach_compose_segfault
with just a missing return value check added.

attach.c

index 32556e6a45277a8e70849ca1120100cbcb1f7ce1..0efeb796dcd1b07a5b5b0ce44dedf19c444dfc20 100644 (file)
--- a/attach.c
+++ b/attach.c
@@ -504,27 +504,40 @@ int mutt_view_attachment (FILE *fp, BODY *a, int flag, HEADER *hdr,
 
     if (flag == M_AS_TEXT)
     {
-      /* just let me see the raw data.
-       *
-       * Don't use mutt_save_attachment() because we want to perform charset
-       * conversion since this will be displayed by the internal pager.
-       */
-      STATE decode_state;
-
-      memset(&decode_state, 0, sizeof(decode_state));
-      decode_state.fpout = safe_fopen(pagerfile, "w");
-      if (!decode_state.fpout)
+      /* just let me see the raw data */
+      if (fp)
       {
-       dprint(1, (debugfile, "mutt_view_attachment:%d safe_fopen(%s) errno=%d %s\n", __LINE__, pagerfile, errno, strerror(errno)));
-       mutt_perror(pagerfile);
-       mutt_sleep(1);
-       goto return_error;
+       /* Viewing from a received message.
+        *
+        * Don't use mutt_save_attachment() because we want to perform charset
+        * conversion since this will be displayed by the internal pager.
+        */
+       STATE decode_state;
+
+       memset(&decode_state, 0, sizeof(decode_state));
+       decode_state.fpout = safe_fopen(pagerfile, "w");
+       if (!decode_state.fpout)
+       {
+         dprint(1, (debugfile, "mutt_view_attachment:%d safe_fopen(%s) errno=%d %s\n", __LINE__, pagerfile, errno, strerror(errno)));
+         mutt_perror(pagerfile);
+         mutt_sleep(1);
+         goto return_error;
+       }
+       decode_state.fpin = fp;
+       decode_state.flags = M_CHARCONV;
+       mutt_decode_attachment(a, &decode_state);
+       if (fclose(decode_state.fpout) == EOF)
+         dprint(1, (debugfile, "mutt_view_attachment:%d fclose errno=%d %s\n", __LINE__, pagerfile, errno, strerror(errno)));
+      }
+      else
+      {
+       /* in compose mode, just copy the file.  we can't use
+        * mutt_decode_attachment() since it assumes the content-encoding has
+        * already been applied
+        */
+       if (mutt_save_attachment(fp, a, pagerfile, 0, NULL))
+         goto return_error;
       }
-      decode_state.fpin = fp;
-      decode_state.flags = M_CHARCONV;
-      mutt_decode_attachment(a, &decode_state);
-      if (fclose(decode_state.fpout) == EOF)
-       dprint(1, (debugfile, "mutt_view_attachment:%d fclose errno=%d %s\n", __LINE__, pagerfile, errno, strerror(errno)));
     }
     else
     {