From owner-svn-src-head@freebsd.org Fri Jul 15 19:43:26 2016 Return-Path: Delivered-To: svn-src-head@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 0047EB9839F; Fri, 15 Jul 2016 19:43:25 +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 B0F801DFD; Fri, 15 Jul 2016 19:43:25 +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 u6FJhOAW096945; Fri, 15 Jul 2016 19:43:24 GMT (envelope-from pfg@FreeBSD.org) Received: (from pfg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u6FJhOUv096943; Fri, 15 Jul 2016 19:43:24 GMT (envelope-from pfg@FreeBSD.org) Message-Id: <201607151943.u6FJhOUv096943@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: pfg set sender to pfg@FreeBSD.org using -f From: "Pedro F. Giffuni" Date: Fri, 15 Jul 2016 19:43:24 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r302911 - head/usr.bin/mail X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Jul 2016 19:43:26 -0000 Author: pfg Date: Fri Jul 15 19:43:24 2016 New Revision: 302911 URL: https://svnweb.freebsd.org/changeset/base/302911 Log: mail(1): Avoid closing negative file descriptors. CID: 1008105, 1008106 MFC after: 1 week Modified: head/usr.bin/mail/quit.c head/usr.bin/mail/v7.local.c Modified: head/usr.bin/mail/quit.c ============================================================================== --- head/usr.bin/mail/quit.c Fri Jul 15 19:14:28 2016 (r302910) +++ head/usr.bin/mail/quit.c Fri Jul 15 19:43:24 2016 (r302911) @@ -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: head/usr.bin/mail/v7.local.c ============================================================================== --- head/usr.bin/mail/v7.local.c Fri Jul 15 19:14:28 2016 (r302910) +++ head/usr.bin/mail/v7.local.c Fri Jul 15 19:43:24 2016 (r302911) @@ -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); } /*