From 7b5db1c35abac2240fffbee2027c3e99b760863c Mon Sep 17 00:00:00 2001 From: Mathieu Lonjaret Date: Sat, 12 Sep 2009 15:25:51 -0400 Subject: [PATCH] libplumb, Mail: fix crash on nil plumb fids http://codereview.appspot.com/116083 --- src/cmd/acme/mail/mail.c | 9 ++++++--- src/libplumb/fid.c | 4 ++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/cmd/acme/mail/mail.c b/src/cmd/acme/mail/mail.c index 14ace323..474d8497 100644 --- a/src/cmd/acme/mail/mail.c +++ b/src/cmd/acme/mail/mail.c @@ -84,9 +84,12 @@ threadmain(int argc, char *argv[]) quotefmtinstall(); /* open these early so we won't miss notification of new mail messages while we read mbox */ - plumbsendfd = plumbopenfid("send", OWRITE|OCEXEC); - plumbseemailfd = plumbopenfid("seemail", OREAD|OCEXEC); - plumbshowmailfd = plumbopenfid("showmail", OREAD|OCEXEC); + if((plumbsendfd = plumbopenfid("send", OWRITE|OCEXEC)) == nil) + fprint(2, "warning: open plumb/send: %r\n"); + if((plumbseemailfd = plumbopenfid("seemail", OREAD|OCEXEC)) == nil) + fprint(2, "warning: open plumb/seemail: %r\n"); + if((plumbshowmailfd = plumbopenfid("showmail", OREAD|OCEXEC)) == nil) + fprint(2, "warning: open plumb/showmail: %r\n"); shortmenu = 0; srvname = "mail"; diff --git a/src/libplumb/fid.c b/src/libplumb/fid.c index ec133c82..017f92c3 100644 --- a/src/libplumb/fid.c +++ b/src/libplumb/fid.c @@ -138,6 +138,10 @@ plumbrecvfid(CFid *fid) Plumbmsg *m; int n, more; + if(fid == nil){ + werrstr("invalid fid"); + return nil; + } buf = malloc(8192); if(buf == nil) return nil;