Subject: bin/4994: /bin/sh argument parsing broken
To: None <gnats-bugs@gnats.netbsd.org>
From: Matthias Scheler <tron@lyssa.owl.de>
List: netbsd-bugs
Date: 02/15/1998 18:51:27
>Number:         4994
>Category:       bin
>Synopsis:       /bin/sh argument parsing broken
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Feb 15 10:05:00 1998
>Last-Modified:
>Originator:     Matthias Scheler
>Organization:
Matthias Scheler                                http://home.owl.de/~tron/
>Release:        980212
>Environment:
System: NetBSD lyssa 1.3C NetBSD 1.3C (LYSSA) #0: Fri Feb 13 00:50:25 MET 1998 tron@lyssa:/usr/src/sys/arch/i386/compile/LYSSA i386

>Description:
NetBSD-current's /bin/sh has a broken argument parsing concerning quotes.
Arguments surrounded by quotation marks end up as seperate arguments in
a shell script.

>How-To-Repeat:
Try this shell script "foobar":
#!/bin/sh
for ARG
do
 echo $ARG
done
exit 0

With 1.3C:
tron@lyssa:~>./foobar "foo bar"
foo
bar

With 1.3:
tron@colwyn:~/lyssa>./foobar "foo bar"
foo bar

>Fix:
Using "src/bin/sh/eval.c" 1.39 instead of 1.42 fixes the problem. The
ony change is this one:

@@ -333,7 +333,7 @@
        arglist.lastp = &arglist.list;
        for (argp = n->nfor.args ; argp ; argp = argp->narg.next) {
                oexitstatus = exitstatus;
-               expandarg(argp, &arglist, EXP_FULL | EXP_TILDE);
+               expandarg(argp, &arglist, EXP_FULL | EXP_TILDE | EXP_RECORD);
                if (evalskip)
                        goto out;
        }
>Audit-Trail:
>Unformatted: