<<< Date Index >>>     <<< Thread Index >>>

Re: smime segmentation fault



On 2005-07-24 14:38:18 +0200, Mads Martin Joergensen wrote:

> (gdb) print *cur
> $5 = (BODY *) 0x0

I'm committing the patch below.

Regards,
-- 
Thomas Roessler · Personal soap box at <http://log.does-not-exist.org/>.




diff -u -r3.15 recvattach.c
--- recvattach.c        3 Feb 2005 17:01:44 -0000       3.15
+++ recvattach.c        24 Jul 2005 14:20:54 -0000
@@ -889,7 +889,7 @@
 
   char helpstr[SHORT_STRING];
   MUTTMENU *menu;
-  BODY *cur;
+  BODY *cur = NULL;
   MESSAGE *msg;
   FILE *fp;
   ATTACHPTR **idx = NULL;
Index: smime.c
===================================================================
RCS file: /cvs/mutt/mutt/smime.c,v
retrieving revision 3.38
diff -u -r3.38 smime.c
--- smime.c     28 Feb 2005 14:37:09 -0000      3.38
+++ smime.c     24 Jul 2005 14:20:54 -0000
@@ -1716,7 +1716,8 @@
   {
     fclose (smimeout); smimeout = NULL;
     mutt_unlink (tmpfname);
-    state_attach_puts (_("[-- Error: unable to create OpenSSL subprocess! 
--]\n"), s);
+    if (s->flags & M_DISPLAY)
+      state_attach_puts (_("[-- Error: unable to create OpenSSL subprocess! 
--]\n"), s);
     return NULL;
   }
   else if ((type & SIGNOPAQUE) &&
@@ -1726,7 +1727,8 @@
   {
     fclose (smimeout); smimeout = NULL;
     mutt_unlink (tmpfname);
-    state_attach_puts (_("[-- Error: unable to create OpenSSL subprocess! 
--]\n"), s);
+    if (s->flags & M_DISPLAY)
+      state_attach_puts (_("[-- Error: unable to create OpenSSL subprocess! 
--]\n"), s);
     return NULL;
   }
 
@@ -1868,6 +1870,7 @@
   size_t tmplength = b->length;
   int origType = b->type;
   FILE *tmpfp=NULL;
+  int rv = 0;
 
   if (!mutt_is_application_smime (b))
     return -1;
@@ -1900,21 +1903,29 @@
   if ((*fpout = safe_fopen (tempfile, "w+")) == NULL)
   {
     mutt_perror (tempfile);
-    return (-1);
+    rv = -1;
+    goto bail;
   }
   mutt_unlink (tempfile);
 
-  *cur = smime_handle_entity (b, &s, *fpout);
+  if (!(*cur = smime_handle_entity (b, &s, *fpout)))
+  {
+    rv = -1;
+    goto bail;
+  }
+    
   (*cur)->goodsig = b->goodsig;
-  (*cur)->badsig = b->badsig;
+  (*cur)->badsig  = b->badsig;
+
+bail:
   b->type = origType;
   b->length = tmplength;
   b->offset = tmpoffset;
-  fclose (tmpfp);
-
-  rewind (*fpout);
-  return (0);
-
+  safe_fclose (&tmpfp);
+  if (*fpout)
+    rewind (*fpout);
+  
+  return rv;
 }