Author: pfg Date: Fri Jul 15 19:43:24 2016 New Revision: 302911 URL: https://svnweb.freebsd.org/changeset/base/302911
Log: mail(1): Avoid closing negative file descriptors. CID: 1008105, 1008106 MFC after: 1 week Modified: head/usr.bin/mail/quit.c head/usr.bin/mail/v7.local.c Modified: head/usr.bin/mail/quit.c ============================================================================== --- head/usr.bin/mail/quit.c Fri Jul 15 19:14:28 2016 (r302910) +++ head/usr.bin/mail/quit.c Fri Jul 15 19:43:24 2016 (r302911) @@ -228,7 +228,8 @@ quit(void) return; } (void)Fclose(obuf); - (void)close(open(mbox, O_CREAT | O_TRUNC | O_WRONLY, 0600)); + if ((fd = open(mbox, O_CREAT | O_TRUNC | O_WRONLY, 0600)) >= 0) + (void)close(fd); if ((obuf = Fopen(mbox, "r+")) == NULL) { warn("%s", mbox); (void)Fclose(ibuf); Modified: head/usr.bin/mail/v7.local.c ============================================================================== --- head/usr.bin/mail/v7.local.c Fri Jul 15 19:14:28 2016 (r302910) +++ head/usr.bin/mail/v7.local.c Fri Jul 15 19:43:24 2016 (r302911) @@ -68,9 +68,12 @@ findmail(char *user, char *buf, int bufl void demail(void) { + int fd; if (value("keep") != NULL || rm(mailname) < 0) - (void)close(open(mailname, O_CREAT | O_TRUNC | O_WRONLY, 0600)); + if ((fd = open(mailname, O_CREAT | O_TRUNC | O_WRONLY, 0600)) >= + 0) + (void)close(fd); } /* _______________________________________________ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"