From owner-freebsd-standards@FreeBSD.ORG Sat Mar 21 22:04:00 2009 Return-Path: Delivered-To: freebsd-standards@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E8EDD1065673 for ; Sat, 21 Mar 2009 22:04:00 +0000 (UTC) (envelope-from jilles@stack.nl) Received: from mx1.stack.nl (meestal-mk5.stack.nl [131.155.140.149]) by mx1.freebsd.org (Postfix) with ESMTP id A8E448FC12 for ; Sat, 21 Mar 2009 22:04:00 +0000 (UTC) (envelope-from jilles@stack.nl) Received: by mx1.stack.nl (Postfix, from userid 65534) id CAAF33F846; Sat, 21 Mar 2009 22:47:00 +0100 (CET) X-Spam-DCC: : X-Spam-Checker-Version: SpamAssassin 3.2.3 (2007-08-08) on meestal-mk5.stack.nl X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,J_CHICKENPOX_63, NO_RELAYS autolearn=no version=3.2.3 X-Spam-Relay-Country: Received: from snail.stack.nl (snail.stack.nl [IPv6:2001:610:1108:5010::131]) by mx1.stack.nl (Postfix) with ESMTP id B37A03FB85; Sat, 21 Mar 2009 22:46:47 +0100 (CET) Received: by snail.stack.nl (Postfix, from userid 1677) id 0931B22892; Sat, 21 Mar 2009 22:46:34 +0100 (CET) Date: Sat, 21 Mar 2009 22:46:34 +0100 From: Jilles Tjoelker To: Oliver Fromme Message-ID: <20090321214634.GA36395@stack.nl> References: <200903181213.n2ICDPpT042350@lurza.secnetix.de> <200903191412.n2JECdbl011120@lurza.secnetix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200903191412.n2JECdbl011120@lurza.secnetix.de> X-Operating-System: FreeBSD 7.1-PRERELEASE i386 User-Agent: Mutt/1.5.18 (2008-05-17) Cc: freebsd-standards@FreeBSD.ORG Subject: Re: Suspecting bug in /bin/sh's IFS X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 21 Mar 2009 22:04:01 -0000 On Thu, Mar 19, 2009 at 03:12:39PM +0100, Oliver Fromme wrote: > Further debugging reveals that this is not a generic > problem with field splitting, but it affects the read > command only. > I tried to use "set" instead of "read": > ORIG_IFS="$IFS" > while read line; do > IFS="$IFS=" > set -- $line > IFS="$ORIG_IFS" > key="$1" > shift > val="$*" > echo "'$key' -- '$val'" > done < config > Now i get correct output for both " \t\n=" and "= \t\n" > as the IFS value. So the bug is in the "read" builtin. > The following patch fixes the problem: > --- bin/sh/miscbltin.c.orig 2006-02-04 15:37:50.000000000 +0100 > +++ bin/sh/miscbltin.c 2009-03-19 15:01:43.000000000 +0100 > @@ -188,7 +188,7 @@ > } > if (c == '\n') > break; > - if (startword && *ifs == ' ' && strchr(ifs, c)) { > + if (startword && strchr(ifs, c)) { > continue; > } > startword = 0; > The bug seems to exist for at least 15 years; the bogus > comparison was already present in the initial import in > the FreeBSD CVS repository in 1994. > Any opinions on this? The code is wrong, but your patched code is also wrong. The read builtin should use the same logic as normal field splitting, with additional rules if there are more fields in the input than variables. I have noticed that NetBSD has already fixed this. I have ported these fixes over: http://www.stack.nl/~jilles/unix/sh-read-split.patch The patch is against RELENG_7, I hope it applies to -CURRENT as well. The NetBSD commit message also refers to http://www.research.att.com/~gsf/public/ifs.sh Just like their /bin/sh, our /bin/sh with the patch now passes the 'read' tests from there (there are still many other failures though). By the way, to avoid all processing by read, one must IFS= read -r VAR. Without the IFS specification, leading and trailing whitespace will still be stripped. -- Jilles Tjoelker