svn commit: r303302 - stable/11/usr.bin/mail

Pedro F. Giffuni pfg at FreeBSD.org
Mon Jul 25 15:03:16 UTC 2016


Author: pfg
Date: Mon Jul 25 15:03:14 2016
New Revision: 303302
URL: https://svnweb.freebsd.org/changeset/base/303302

Log:
  MFC r302911:
  mail(1): Avoid closing negative file descriptors.
  
  CID:		1008105, 1008106
  Approved by:	re (gjb)

Modified:
  stable/11/usr.bin/mail/quit.c
  stable/11/usr.bin/mail/v7.local.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/usr.bin/mail/quit.c
==============================================================================
--- stable/11/usr.bin/mail/quit.c	Mon Jul 25 14:53:04 2016	(r303301)
+++ stable/11/usr.bin/mail/quit.c	Mon Jul 25 15:03:14 2016	(r303302)
@@ -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: stable/11/usr.bin/mail/v7.local.c
==============================================================================
--- stable/11/usr.bin/mail/v7.local.c	Mon Jul 25 14:53:04 2016	(r303301)
+++ stable/11/usr.bin/mail/v7.local.c	Mon Jul 25 15:03:14 2016	(r303302)
@@ -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);
 }
 
 /*


More information about the svn-src-all mailing list