Subject: Re: bin/33472: /bin/sh does not expand "$@" correctly
To: None <gnats-admin@netbsd.org, netbsd-bugs@netbsd.org, rillig@NetBSD.org>
From: David Laight <david@l8s.co.uk>
List: netbsd-bugs
Date: 05/14/2006 20:35:02
The following reply was made to PR bin/33472; it has been noted by GNATS.

From: David Laight <david@l8s.co.uk>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: bin/33472: /bin/sh does not expand "$@" correctly
Date: Sun, 14 May 2006 21:42:51 +0100

 On Fri, May 12, 2006 at 07:25:03PM +0000, rillig@NetBSD.org wrote:
 > >Number:         33472
 > >Category:       bin
 > >Synopsis:       /bin/sh does not expand "$@" correctly
 
 > between NetBSD 2.0.2 and NetBSD 3.0 a bug has been introduced into
 > expand.c which causes the following behavior:
 > 
 > $ set -- "" ""
 > $ echo $#
 > 2
 > $ echo "$@" | sed s,\$,EOL,
 > EOL
 > $
 > 
 > The correct behavior would be (and had been) to output one space before
 > the "EOL" string.
 
 This seems to fix it....
 The second change just deletes the commented out code, the removal of
 which caused the bug.
 
 Index: expand.c
 ===================================================================
 RCS file: /cvsroot/src/bin/sh/expand.c,v
 retrieving revision 1.73
 diff -u -p -r1.73 expand.c
 --- expand.c    18 Mar 2006 05:25:56 -0000      1.73
 +++ expand.c    14 May 2006 20:29:23 -0000
 @@ -872,8 +872,8 @@ numvar:
 		if (flag & EXP_FULL && quoted) {
 			for (ap = shellparam.p ; (p = *ap++) != NULL ; ) {
 				STRTODEST(p);
 -				if (*ap)
 -					STPUTC('\0', expdest);
 +				/* Nul forces a parameter split inside "" */
 +				STPUTC('\0', expdest);
 			}
 			break;
 		}
 @@ -1034,7 +1034,7 @@ ifsbreakup(char *string, struct arglist 
 	 * Some recent clarification of the Posix spec say that it
 	 * should only generate one....
 	 */
 -	if (*start /* || (!ifsspc && start > string) */) {
 +	if (*start) {
 		sp = (struct strlist *)stalloc(sizeof *sp);
 		sp->text = start;
 		*arglist->lastp = sp;
 
 	David
 
 -- 
 David Laight: david@l8s.co.uk