From owner-freebsd-rc@FreeBSD.ORG Fri Jun 9 04:56:30 2006 Return-Path: X-Original-To: freebsd-rc@freebsd.org Delivered-To: freebsd-rc@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E2C4916A418 for ; Fri, 9 Jun 2006 04:56:29 +0000 (UTC) (envelope-from brdavis@odin.ac.hmc.edu) Received: from odin.ac.hmc.edu (Odin.AC.HMC.Edu [134.173.32.75]) by mx1.FreeBSD.org (Postfix) with ESMTP id 81F9143D72 for ; Fri, 9 Jun 2006 04:56:29 +0000 (GMT) (envelope-from brdavis@odin.ac.hmc.edu) Received: from odin.ac.hmc.edu (localhost.localdomain [127.0.0.1]) by odin.ac.hmc.edu (8.13.0/8.13.0) with ESMTP id k594uTSp018679; Thu, 8 Jun 2006 21:56:29 -0700 Received: (from brdavis@localhost) by odin.ac.hmc.edu (8.13.0/8.13.0/Submit) id k594uTPI018678; Thu, 8 Jun 2006 21:56:29 -0700 Date: Thu, 8 Jun 2006 21:56:28 -0700 From: Brooks Davis To: Doug White Message-ID: <20060609045628.GB25288@odin.ac.hmc.edu> References: <200606082130.k58LUYQO069255@freefall.freebsd.org> <20060609005422.GA25288@odin.ac.hmc.edu> <20060608175640.R50887@carver.gumbysoft.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="kXdP64Ggrk/fb43R" Content-Disposition: inline In-Reply-To: <20060608175640.R50887@carver.gumbysoft.com> User-Agent: Mutt/1.4.1i X-Virus-Scanned: by amavisd-new Cc: freebsd-rc@freebsd.org Subject: Re: conf/94377 : [patch] /etc/rc.d/sshd improperly tests random dev state X-BeenThere: freebsd-rc@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Discussion related to /etc/rc.d design and implementation." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 09 Jun 2006 04:56:30 -0000 --kXdP64Ggrk/fb43R Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Jun 08, 2006 at 05:58:29PM -0700, Doug White wrote: > On Thu, 8 Jun 2006, Brooks Davis wrote: >=20 > >On Thu, Jun 08, 2006 at 09:30:34PM +0000, Doug White wrote: > >>The following reply was made to PR conf/94377; it has been noted by GNA= TS. > >> > >>From: Doug White > >>To: Rostislav Krasny > >>Cc: Florent Thoumie , Doug White , > >> bug-followup@FreeBSD.org > >>Subject: Re: conf/94377 : [patch] /etc/rc.d/sshd improperly tests rando= m=20 > >>dev > >> state > >>Date: Thu, 8 Jun 2006 10:36:05 -0700 (PDT) > >> > >> On Thu, 8 Jun 2006, Rostislav Krasny wrote: > >> > >>> I've seen that patch just today, when it is already MFCed. I think it > >>> could be simpler. Instead of > >>> > >>> [ "x${seeded}" !=3D "x" ] && [ ${seeded} -eq 0 ] > >>> > >>> you can write just > >>> > >>> [ "${seeded}" =3D "0" ] > >>> > >>> and it will be still correct against sysctl failing and returning an > >>> empty string. > >> > >> No, because if ${seeded} is empty, the shell interprets the test as > >> > >> [ =3D "0" ] > >> > >> which results in a syntax error. The 'x' in the first test is=20 > >> significant. > > > >Not true. The 'x' bit has been unnecessicary 31337 for quite some > >time IMO. If you didn't quote ${seeded} then it would be, but > >"${variable_that_expands_to_null}" is "". Otherwise -z and -n wouldn't > >work. >=20 > -z and -n are unary operations. They just check if the *have* an argument= .=20 > =3D is a comparison operation and requires two operands. I think they do actually check the argument, but weird things happen if you pass them an unquoted argument (both -z and -n return true if you use normal [ testargs ]; syntax). I'm not quite sure what's happening. > If it offends you two that much then file a new PR. I honestly don't give= =20 > a crap. I don't care about the change (at least not enough to do anything about it). It's fine, particularly since there's plenty of code like it in the system. I only responded because the belief that the x"${var}" idiom is necessicary is widely held for no reason I can figure out except perhaps that it's so widely used the obvious inference is that there must be some reason for doing so. :) I can only assume that some ancient system didn't have -n and -z and didn't handle null arguments properly. The following test code illustrates that the proposed solution would work and an oddity if you don't quote the arguments passed to -z and -n. -- Brooks ------ #!/bin/sh nullvar=3D zerovar=3D0 if [ -z "${nullvar}" ]; then echo "nullvar is empty" else echo "nullvar is not empty" fi if [ "${nullvar}" =3D "0" ]; then echo "nullvar equals 0" else echo "nullvar does not equal 0" fi if [ -z "${zerovar}" ]; then echo "zerovar is empty" else echo "zerovar is not empty" fi if [ "${zerovar}" =3D "0" ]; then echo "zerovar equals 0" else echo "zerovar does not equal 0" fi echo 'testing "-z ${nullvar}"' if [ -z ${nullvar} ]; then echo true else echo false fi echo 'testing "-n ${nullvar}"' if [ -n ${nullvar} ]; then echo true else echo false fi ------ --=20 Any statement of the form "X is the one, true Y" is FALSE. PGP fingerprint 655D 519C 26A7 82E7 2529 9BF0 5D8E 8BE9 F238 1AD4 --kXdP64Ggrk/fb43R Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQFEiP98XY6L6fI4GtQRAkBeAJ9bwclBhsdDi7I+HgLTGgW5kccVrQCeNXFs XYnVbMV4H7YvU1Ij2yH+jSo= =8Gns -----END PGP SIGNATURE----- --kXdP64Ggrk/fb43R--