From owner-svn-src-head@FreeBSD.ORG Wed Jul 24 19:08:45 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 69C4192E; Wed, 24 Jul 2013 19:08:45 +0000 (UTC) (envelope-from pawel@dawidek.net) Received: from mail.dawidek.net (garage.dawidek.net [91.121.88.72]) by mx1.freebsd.org (Postfix) with ESMTP id 2EE832725; Wed, 24 Jul 2013 19:08:44 +0000 (UTC) Received: from localhost (89-73-195-149.dynamic.chello.pl [89.73.195.149]) by mail.dawidek.net (Postfix) with ESMTPSA id 78367DFB; Wed, 24 Jul 2013 20:55:21 +0200 (CEST) Date: Wed, 24 Jul 2013 21:01:01 +0200 From: Pawel Jakub Dawidek To: Ulrich =?iso-8859-1?Q?Sp=F6rlein?= , src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r253457 - head/usr.bin/uniq Message-ID: <20130724190101.GA1400@garage.freebsd.pl> References: <201307182211.r6IMBRYC091291@svn.freebsd.org> <20130724125332.GC9092@acme.spoerlein.net> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="J/dobhs11T7y2rNN" Content-Disposition: inline In-Reply-To: <20130724125332.GC9092@acme.spoerlein.net> X-OS: FreeBSD 10.0-CURRENT amd64 User-Agent: Mutt/1.5.21 (2010-09-15) X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 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, 24 Jul 2013 19:08:45 -0000 --J/dobhs11T7y2rNN Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Jul 24, 2013 at 02:53:32PM +0200, Ulrich Sp=F6rlein wrote: > On Thu, 2013-07-18 at 22:11:27 +0000, Pawel Jakub Dawidek wrote: > > Author: pjd > > Date: Thu Jul 18 22:11:27 2013 > > New Revision: 253457 > > URL: http://svnweb.freebsd.org/changeset/base/253457 > >=20 > > Log: > > Close uniq(1) in the capability mode sandbox and limit descriptors us= ing > > capability rights. > >=20 > > Modified: > > head/usr.bin/uniq/uniq.c > >=20 > > Modified: head/usr.bin/uniq/uniq.c > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D > > --- head/usr.bin/uniq/uniq.c Thu Jul 18 21:56:10 2013 (r253456) > > +++ head/usr.bin/uniq/uniq.c Thu Jul 18 22:11:27 2013 (r253457) > > @@ -128,8 +145,34 @@ main (int argc, char *argv[]) > > ofp =3D stdout; > > if (argc > 0 && strcmp(argv[0], "-") !=3D 0) > > ifp =3D file(ifn =3D argv[0], "r"); > > + if (cap_rights_limit(fileno(ifp), CAP_FSTAT | CAP_READ) < 0 && > > + errno !=3D ENOSYS) { > > + err(1, "unable to limit rights for %s", ifn); > > + } > > + rights =3D CAP_FSTAT | CAP_WRITE; > > if (argc > 1) > > ofp =3D file(argv[1], "w"); > > + else > > + rights |=3D CAP_IOCTL; > > + if (cap_rights_limit(fileno(ofp), rights) < 0 && errno !=3D ENOSYS) { > > + err(1, "unable to limit rights for %s", > > + argc > 1 ? argv[1] : "stdout"); > > + } > > + if ((rights & CAP_IOCTL) !=3D 0) { > > + unsigned long cmd; > > + > > + cmd =3D TIOCGETA; /* required by isatty(3) in printf(3) */ > > + > > + if (cap_ioctls_limit(fileno(ofp), &cmd, 1) < 0 && > > + errno !=3D ENOSYS) { > > + err(1, "unable to limit ioctls for %s", > > + argc > 1 ? argv[1] : "stdout"); > > + } > > + } >=20 > Deadcode, found by Coverity Scan, CID 1054780 (please mention in your > fix-commit). You check for argc > 1 at line 153, only if that is false > (meaning argc=3D=3D1) do you set CAP_IOCTL. So on line 169 argc cannot be= >1 > and the result is always "stdout". Interesting. I was aware of this, but left this err() call for consistency in case the condition changes in the future. --=20 Pawel Jakub Dawidek http://www.wheelsystems.com FreeBSD committer http://www.FreeBSD.org Am I Evil? Yes, I Am! http://mobter.com --J/dobhs11T7y2rNN Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.20 (FreeBSD) iEYEARECAAYFAlHwJG0ACgkQForvXbEpPzQk2wCg8RdABUGsLeO5sChcbppoOC73 deoAn3pTLpgpHsDGkpRq6fBnldn8Naua =2EPc -----END PGP SIGNATURE----- --J/dobhs11T7y2rNN--