Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 19 Mar 2009 15:12:39 +0100 (CET)
From:      Oliver Fromme <olli@lurza.secnetix.de>
To:        freebsd-standards@FreeBSD.ORG
Subject:   Re: Suspecting bug in /bin/sh's IFS
Message-ID:  <200903191412.n2JECdbl011120@lurza.secnetix.de>
In-Reply-To: <200903181213.n2ICDPpT042350@lurza.secnetix.de>

next in thread | previous in thread | raw e-mail | index | archive | help
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?

Best regards
   Oliver

-- 
Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing b. M.
Handelsregister: Registergericht Muenchen, HRA 74606,  Geschäftsfuehrung:
secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mün-
chen, HRB 125758,  Geschäftsführer: Maik Bachmann, Olaf Erb, Ralf Gebhart

FreeBSD-Dienstleistungen, -Produkte und mehr:  http://www.secnetix.de/bsd

"Whatever happened to the days when hacking started
at the cerebral cortex, and not at the keyboard?"
  --  Sid on userfriendly.org by Illiad, 2007-06-20



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200903191412.n2JECdbl011120>