Search the web
Sign In
New User? Sign Up
mutt-dev · Mutt Mail User Agent Developers
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Show off your group to the world. Share a photo of your group with us.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
PATCH mutt_create_filter*() return values   Message List  
Reply | Forward Message #11295 of 24304 |
The attached patch adds some more error checking and should help to
avoid some crashes.

--
Thomas Roessler http://log.does-not-exist.org/


Tue Jun 5, 2001 7:56 am

roessler@...
Send Email Send Email

Index: attach.c
===================================================================
RCS file: /home/roessler/cvsroot/mutt/attach.c,v
retrieving revision 2.25
diff -u -r2.25 attach.c
--- attach.c 2001/04/26 13:36:33 2.25
+++ attach.c 2001/06/05 07:54:49
@@ -600,7 +600,8 @@
{
pid_t thepid;
int out = -1;
-
+ int rv = 0;
+
if (outfile && *outfile)
if ((out = safe_open (outfile, O_CREAT | O_EXCL | O_WRONLY)) < 0)
{
@@ -623,9 +624,15 @@
else
thepid = mutt_create_filter (path, &s.fpout, NULL, NULL);

+ if (thepid < 0)
+ {
+ mutt_perror _("Can't create filter");
+ goto bail;
+ }
+
s.fpin = fp;
mutt_decode_attachment (b, &s);
- fclose (s.fpout);
+ safe_fclose (&s.fpout);
}
else
{
@@ -649,17 +656,28 @@
else
thepid = mutt_create_filter (path, &ofp, NULL, NULL);

+ if (thepid < 0)
+ {
+ mutt_perror _("Can't create filter");
+ safe_fclose (&ifp);
+ goto bail;
+ }
+
mutt_copy_stream (ifp, ofp);
- fclose (ofp);
- fclose (ifp);
+ safe_fclose (&ofp);
+ safe_fclose (&ifp);
}

+ rv = 1;
+
+bail:
+
if (outfile && *outfile)
close (out);

- if (mutt_wait_filter (thepid) != 0 || option (OPTWAITKEY))
+ if (rv == 0 || mutt_wait_filter (thepid) != 0 || option (OPTWAITKEY))
mutt_any_key_to_continue (NULL);
- return 1;
+ return rv;
}

/* returns 0 on success, -1 on error */
@@ -918,10 +936,16 @@
return (0);
}

- thepid = mutt_create_filter (command, &fpout, NULL, NULL);
+ if ((thepid = mutt_create_filter (command, &fpout, NULL, NULL)) < 0)
+ {
+ mutt_perror _("Can't create filter");
+ rfc1524_free_entry (&entry);
+ safe_fclose (&ifp);
+ return 0;
+ }
mutt_copy_stream (ifp, fpout);
- fclose (fpout);
- fclose (ifp);
+ safe_fclose (&fpout);
+ safe_fclose (&ifp);
if (mutt_wait_filter (thepid) || option (OPTWAITKEY))
mutt_any_key_to_continue (NULL);
}
@@ -950,22 +974,34 @@
/* decode and print */

int rc = 0;
-
+
+ ifp = NULL;
+ fpout = NULL;
+
mutt_mktemp (newfile);
if (mutt_decode_save_attachment (fp, a, newfile, 0, 0) == 0)
{
- if ((ifp = fopen (newfile, "r")) != NULL)
+ if ((ifp = fopen (newfile, "r")) == NULL)
+ {
+ mutt_perror ("fopen");
+ goto bail0;
+ }
+
+ mutt_endwin (NULL);
+ if ((thepid = mutt_create_filter (NONULL(PrintCmd), &fpout, NULL, NULL))
< 0)
{
- mutt_endwin (NULL);
- thepid = mutt_create_filter (NONULL(PrintCmd), &fpout, NULL, NULL);
- mutt_copy_stream (ifp, fpout);
- fclose (ifp);
- fclose (fpout);
- if (mutt_wait_filter (thepid) != 0 || option (OPTWAITKEY))
- mutt_any_key_to_continue (NULL);
- rc = 1;
+ mutt_perror _("Can't create filter");
+ goto bail0;
}
+
+ mutt_copy_stream (ifp, fpout);
+ if (mutt_wait_filter (thepid) != 0 || option (OPTWAITKEY))
+ mutt_any_key_to_continue (NULL);
+ rc = 1;
}
+ bail0:
+ safe_fclose (&ifp);
+ safe_fclose (&fpout);
mutt_unlink (newfile);
return rc;
}
Index: commands.c
===================================================================
RCS file: /home/roessler/cvsroot/mutt/commands.c,v
retrieving revision 2.44
diff -u -r2.44 commands.c
--- commands.c 2001/05/21 08:42:06 2.44
+++ commands.c 2001/06/05 07:49:16
@@ -124,7 +124,7 @@
if (filterpid < 0)
{
mutt_error (_("Cannot create display filter"));
- fclose (fpfilterout);
+ safe_fclose (&fpfilterout);
unlink (tempfile);
return 0;
}
@@ -324,9 +324,14 @@
mutt_endwin (NULL);
#endif

- thepid = mutt_create_filter (cmd, &fpout, NULL, NULL);
+ if ((thepid = mutt_create_filter (cmd, &fpout, NULL, NULL)) < 0)
+ {
+ mutt_perror _("Can't create filter process");
+ return 1;
+ }
+
pipe_msg (h, fpout, decode);
- fclose (fpout);
+ safe_fclose (&fpout);
rc = mutt_wait_filter (thepid);
}
else
@@ -358,11 +363,15 @@
{
mutt_message_hook (Context, Context->hdrs[Context->v2r[i]], M_MESSAGEHOOK);
mutt_endwin (NULL);
- thepid = mutt_create_filter (cmd, &fpout, NULL, NULL);
+ if ((thepid = mutt_create_filter (cmd, &fpout, NULL, NULL)) < 0)
+ {
+ mutt_perror _("Can't create filter process");
+ return 1;
+ }
pipe_msg (Context->hdrs[Context->v2r[i]], fpout, decode);
/* add the message separator */
if (sep) fputs (sep, fpout);
- fclose (fpout);
+ safe_fclose (&fpout);
if (mutt_wait_filter (thepid) != 0)
rc = 1;
}
@@ -371,7 +380,11 @@
else
{
mutt_endwin (NULL);
- thepid = mutt_create_filter (cmd, &fpout, NULL, NULL);
+ if ((thepid = mutt_create_filter (cmd, &fpout, NULL, NULL)) < 0)
+ {
+ mutt_perror _("Can't create filter process");
+ return 1;
+ }
for (i = 0; i < Context->vcount; i++)
{
if (Context->hdrs[Context->v2r[i]]->tagged)
@@ -382,7 +395,7 @@
if (sep) fputs (sep, fpout);
}
}
- fclose (fpout);
+ safe_fclose (&fpout);
if (mutt_wait_filter (thepid) != 0)
rc = 1;
}
Index: handler.c
===================================================================
RCS file: /home/roessler/cvsroot/mutt/handler.c,v
retrieving revision 2.40
diff -u -r2.40 handler.c
--- handler.c 2001/05/20 22:35:29 2.40
+++ handler.c 2001/06/05 07:53:21
@@ -1506,18 +1506,26 @@

if(!piped)
{
- fclose (fpin);
+ safe_fclose (&fpin);
thepid = mutt_create_filter (command, NULL, &fpout, &fperr);
}
else
{
- unlink(tempfile);
- fflush(fpin);
- rewind(fpin);
+ unlink (tempfile);
+ fflush (fpin);
+ rewind (fpin);
thepid = mutt_create_filter_fd (command, NULL, &fpout, &fperr,
fileno(fpin), -1, -1);
}

+ if (thepid < 0)
+ {
+ mutt_perror _("Can't create filter");
+ if (s->flags & M_DISPLAY)
+ state_printf (s, _("[-- Can't run %s. --]\n"), command);
+ goto bail;
+ }
+
if (s->prefix)
{
while (fgets (buffer, sizeof(buffer), fpout) != NULL)
@@ -1554,12 +1562,14 @@
mutt_copy_stream (fperr, s->fpout);
}
}
+
+ bail:
+ safe_fclose (&fpout);
+ safe_fclose (&fperr);

- fclose (fpout);
- fclose (fperr);
mutt_wait_filter (thepid);
- if(piped)
- fclose(fpin);
+ if (piped)
+ safe_fclose (&fpin);
else
mutt_unlink (tempfile);



Attachment
attachment
Type:
application/pgp-signature
Forward
Message #11295 of 24304 |
Expand Messages Author Sort by Date

The attached patch adds some more error checking and should help to avoid some crashes. -- Thomas Roessler...
Thomas Roessler
roessler@...
Send Email
Jun 5, 2001
8:17 am
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help