Suspecting bug in /bin/sh's IFS
Oliver Fromme
olli at lurza.secnetix.de
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":
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
More information about the freebsd-standards
mailing list