From owner-svn-src-all@freebsd.org Mon Jul 25 15:03:16 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 39460BA38E9; Mon, 25 Jul 2016 15:03:16 +0000 (UTC) (envelope-from pfg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 01FBF1576; Mon, 25 Jul 2016 15:03:15 +0000 (UTC) (envelope-from pfg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u6PF3FjX058070; Mon, 25 Jul 2016 15:03:15 GMT (envelope-from pfg@FreeBSD.org) Received: (from pfg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u6PF3FEV058068; Mon, 25 Jul 2016 15:03:15 GMT (envelope-from pfg@FreeBSD.org) Message-Id: <201607251503.u6PF3FEV058068@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: pfg set sender to pfg@FreeBSD.org using -f From: "Pedro F. Giffuni" Date: Mon, 25 Jul 2016 15:03:15 +0000 (UTC) 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 X-SVN-Group: stable-11 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Jul 2016 15:03:16 -0000 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); } /*