🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.bugs.misc
Article #88

ksh returns erroneous data when there are trailing empty fields

#88
From: Richard Doty
Date: Thu, 26 Nov 1987 01:18
44 lines
1714 bytes
Index:	ksh/sh/name.c

Description:
	When using a non-default input field separator (such as ':'),
	trailing empty data fields cause ksh to underflow an input
	stack, and thus fail to correctly null-terminate the string
	before assigning it to the variable being read.

	This bug is present in both ksh (Version 02/21/85) and ksh-i
	(Version 06/03/86a) as distributed by the AT&T toolchest.

Repeat-By:
	Execute this shell file:

IFS=:$IFS
while read f1 f2 f3
do	echo f1=\""$f1"\" f2=\""$f2"\" f3=\""$f3"\"
done <<E-O-F
rec1.f1:rec1.f2:rec1.f3
rec2.f1:rec2.f2::
rec3.f1:rec3.f2::
E-O-F

# correct behavior:
#
#	$ sh g
#	f1="rec1.f1" f2="rec1.f2" f3="rec1.f3"
#	f1="rec2.f1" f2="rec2.f2" f3=":"
#	f1="rec3.f1" f2="rec3.f2" f3=":"
#	$
#
# incorrect behavior (note field 3):
#
#	$ ENV= ksh g
#	f1="rec1.f1" f2="rec1.f2" f3="rec1.f3"
#	f1="rec2.f1" f2="rec2.f2" f3=":ec2.f2"
#	f1="rec3.f1" f2="rec3.f2" f3=":ec3.f2"
#	$

Fix:
	In readvar() in name.c, where the top of the stack is being
	decremented past any trailing separators, make sure it doesn't
	go past the bottom of the stack.
Technical Details
Message-ID: <121@puffin.USS.TEK.COM>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!husc6!mit-eddie!uw-beaver!tektronix!tekgen!puffin!rad

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!husc6!mit-eddie!uw-beaver!tektronix!tekgen!puffin!rad
From: rad@puffin.USS.TEK.COM (Richard Doty)
Newsgroups: comp.bugs.misc
Subject: ksh returns erroneous data when there are trailing empty fields
Message-ID: <121@puffin.USS.TEK.COM>
Date: Wed, 25-Nov-87 20:18:08 EST
Article-I.D.: puffin.121
Posted: Wed Nov 25 20:18:08 1987
Date-Received: Sun, 29-Nov-87 12:44:49 EST
Reply-To: rad@puffin.uss.tek.com (Richard Doty)
Organization: Unix Systems Support, Tektronix, Inc., Beaverton, OR
Lines: 44