Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 25 Jul 2016 15:05:01 +0000 (UTC)
From:      "Pedro F. Giffuni" <pfg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org
Subject:   svn commit: r303305 - stable/9/usr.bin/mail
Message-ID:  <201607251505.u6PF51It058282@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: pfg
Date: Mon Jul 25 15:05:01 2016
New Revision: 303305
URL: https://svnweb.freebsd.org/changeset/base/303305

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

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

Modified: stable/9/usr.bin/mail/quit.c
==============================================================================
--- stable/9/usr.bin/mail/quit.c	Mon Jul 25 15:04:17 2016	(r303304)
+++ stable/9/usr.bin/mail/quit.c	Mon Jul 25 15:05:01 2016	(r303305)
@@ -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/9/usr.bin/mail/v7.local.c
==============================================================================
--- stable/9/usr.bin/mail/v7.local.c	Mon Jul 25 15:04:17 2016	(r303304)
+++ stable/9/usr.bin/mail/v7.local.c	Mon Jul 25 15:05:01 2016	(r303305)
@@ -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?201607251505.u6PF51It058282>