From owner-svn-src-head@freebsd.org Wed Jan 4 23:36:53 2017 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 593E4C9F903; Wed, 4 Jan 2017 23:36:53 +0000 (UTC) (envelope-from jilles@stack.nl) Received: from mailout.stack.nl (mailout05.stack.nl [IPv6:2001:610:1108:5010::202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mailout.stack.nl", Issuer "CA Cert Signing Authority" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 2809D1C3B; Wed, 4 Jan 2017 23:36:53 +0000 (UTC) (envelope-from jilles@stack.nl) Received: from snail.stack.nl (snail.stack.nl [IPv6:2001:610:1108:5010::131]) by mailout.stack.nl (Postfix) with ESMTP id 9BFD430; Thu, 5 Jan 2017 00:36:50 +0100 (CET) Received: by snail.stack.nl (Postfix, from userid 1677) id 8B7E928494; Thu, 5 Jan 2017 00:36:50 +0100 (CET) Date: Thu, 5 Jan 2017 00:36:50 +0100 From: Jilles Tjoelker To: Ngie Cooper Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r311233 - head/contrib/netbsd-tests/fs/tmpfs Message-ID: <20170104233650.GB17765@stack.nl> References: <201701040246.v042kaEh039041@repo.freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <201701040246.v042kaEh039041@repo.freebsd.org> User-Agent: Mutt/1.5.21 (2010-09-15) X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 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: Wed, 04 Jan 2017 23:36:53 -0000 On Wed, Jan 04, 2017 at 02:46:36AM +0000, Ngie Cooper wrote: > Author: ngie > Date: Wed Jan 4 02:46:36 2017 > New Revision: 311233 > URL: https://svnweb.freebsd.org/changeset/base/311233 > Log: > Fix Coverity issues > - Initialize .sun_len before passing it to strlcpy and bind. > - Close fd on error > MFC after: 3 days > Reported by: Coverity > CID: 978283, 979581 > Modified: > head/contrib/netbsd-tests/fs/tmpfs/h_tools.c > Modified: head/contrib/netbsd-tests/fs/tmpfs/h_tools.c > ============================================================================== > --- head/contrib/netbsd-tests/fs/tmpfs/h_tools.c Wed Jan 4 02:43:33 2017 (r311232) > +++ head/contrib/netbsd-tests/fs/tmpfs/h_tools.c Wed Jan 4 02:46:36 2017 (r311233) > @@ -243,12 +243,19 @@ sockets_main(int argc, char **argv) > return EXIT_FAILURE; > } > > +#ifdef __FreeBSD__ > + addr.sun_len = sizeof(addr.sun_path); > + (void)strlcpy(addr.sun_path, argv[1], addr.sun_len); > +#else > (void)strlcpy(addr.sun_path, argv[1], sizeof(addr.sun_path)); > +#endif > addr.sun_family = PF_UNIX; > - > error = bind(fd, (struct sockaddr *)&addr, sizeof(addr)); > if (error == -1) { > warn("connect"); > +#ifdef __FreeBSD__ > + (void)close(fd); > +#endif > return EXIT_FAILURE; > } > It would be better to avoid naming the non-portable sun_len field if it is just to make Coverity happy. I suggest initializing the structure with designated initializers or memset(). Apart from that, the value for sun_len is wrong; it should be the length of the whole structure and not just the sun_path part. Fortunately, the field is ignored by bind(), which uses the addrlen parameter instead. On a more general note, refactoring tests without a way to verify they have not been changed to always pass is risky :( -- Jilles Tjoelker