Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 15 Jul 2016 19:43:24 +0000 (UTC)
From:      "Pedro F. Giffuni" <pfg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r302911 - head/usr.bin/mail
Message-ID:  <201607151943.u6FJhOUv096943@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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);
 }
 
 /*



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201607151943.u6FJhOUv096943>