Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 25 Jul 2016 15:03:15 +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-11@freebsd.org
Subject:   svn commit: r303302 - stable/11/usr.bin/mail
Message-ID:  <201607251503.u6PF3FEV058068@repo.freebsd.org>

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



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