Suspecting bug in /bin/sh's IFS

Oliver Fromme olli at
Thu Mar 19 07:13:04 PDT 2009

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":

 while read line; do
         set -- $line
         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')
-		if (startword && *ifs == ' ' && strchr(ifs, c)) {
+		if (startword && strchr(ifs, c)) {
 		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 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:

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

More information about the freebsd-standards mailing list