From owner-svn-src-stable-9@freebsd.org Mon Jul 25 15:05:02 2016 Return-Path: Delivered-To: svn-src-stable-9@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 4EE76BA3ABF; Mon, 25 Jul 2016 15:05:02 +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 2178F1A15; Mon, 25 Jul 2016 15:05:02 +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 u6PF51Im058284; Mon, 25 Jul 2016 15:05:01 GMT (envelope-from pfg@FreeBSD.org) Received: (from pfg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u6PF51It058282; Mon, 25 Jul 2016 15:05:01 GMT (envelope-from pfg@FreeBSD.org) Message-Id: <201607251505.u6PF51It058282@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:05:01 +0000 (UTC) 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 X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-9@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 9-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Jul 2016 15:05:02 -0000 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); } /*