SVR4 /bin/sh BUG

Rick Richardson rick at digibd.com
Sun May 19 05:57:52 AEST 1991


Here's a nasty little surprise I discovered when porting some
Bourne shell code from SVR3 to SVR4.  The tidbit below serves only
to demonstrate the bug.  The real code did something useful,
at least it did on SVR3. :-)

I checked UHC and AT&T flavors of SVR4.  Don't know how many
others have the bug.

-Rick

#---------------
#
#	Demonstrates bug in SVR4 /bin/sh
#	Works OK with /bin/sh on SVR3 and XENIX
#	Works OK with /bin/ksh on SVR4
#
#	Should output the first line of /etc/passwd four times
#	Only does it three times on SVR4 and then hangs
#
#	Seems to be related to changing fd0 in a function
#
read_by_func() {
	exec 3<&0 0<$1
	read x
	echo $x
	exec 0<&3 3<&-
}

exec 3<&0 0</etc/passwd
read x
echo $x
exec 0<&3 3<&-

exec 3<&0 0</etc/passwd
read x
echo $x
exec 0<&3 3<&-

read_by_func /etc/passwd

# Gets stuck here with /bin/sh...
read_by_func /etc/passwd
exit
#---------------
-- 
Rick Richardson		Email: rick at digibd.com
Senior MTS		Fax: (612) 943-0803
DigiBoard, Inc.		Tel: (612) 943-5383



More information about the Comp.unix.sysv386 mailing list