conf/94377 : [patch] /etc/rc.d/sshd improperly tests random dev state

Rostislav Krasny rosti.bsd at gmail.com
Thu Jun 8 23:00:48 UTC 2006


The following reply was made to PR conf/94377; it has been noted by GNATS.

From: Rostislav Krasny <rosti.bsd at gmail.com>
To: Doug White <dwhite at gumbysoft.com>
Cc: Florent Thoumie <flz at FreeBSD.org>, bug-followup at FreeBSD.org
Subject: Re: conf/94377 : [patch] /etc/rc.d/sshd improperly tests random dev
 state
Date: Thu, 8 Jun 2006 22:03:58 +0300

 On Thu, 8 Jun 2006 10:36:05 -0700 (PDT)
 Doug White <dwhite at gumbysoft.com> wrote:
 
 > 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}" != "x" ] && [ ${seeded} -eq 0 ]
 > >
 > > you can write just
 > >
 > > [ "${seeded}" = "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
 > 
 > [ = "0" ]
 > 
 > which results in a syntax error. The 'x' in the first test is significant.
 
 No, if ${seeded} is empty, the shell interprets the
 
 [ "${seeded}" = "0" ]
 
 as
 
 [ "" = "0" ]
 
 which has no syntax error because the ${seeded} is between the double
 quotes. Try following simple script to test it:
 
 #!/bin/sh
 
 seeded=`sysctl -n kern.random.sys.seededdd 2>/dev/null`
 echo ${seeded}
 
 if [ "${seeded}" = "0" ]
 then
         echo true
 else
         echo false
 fi
 
 The sysctl will fail because of a wrong variable name, but no syntax
 error will occur. If you remove the double quotes around the ${seeded}
 only then a syntaxt error will happen.
 
 If on CURRENT it works differently then most likely it has a bug
 in sh(1).


More information about the freebsd-rc mailing list