Subject: Re: bin/19893: /bin/sh doesn't parse "sh -c 'echo $0 $*' -x a b" properly
To: None <netbsd-bugs@netbsd.org>
From: David Laight <david@l8s.co.uk>
List: netbsd-bugs
Date: 01/17/2003 17:38:08
> >Fix:

Index: options.c
===================================================================
RCS file: /cvsroot/src/bin/sh/options.c,v
retrieving revision 1.32
diff -u -r1.32 options.c
--- options.c	2002/11/24 22:35:42	1.32
+++ options.c	2003/01/17 17:32:49
@@ -118,8 +118,13 @@
 		commandname = arg0;
 	}
 	/* POSIX 1003.2: first arg after -c cmd is $0, remainder $1... */
-	if (argptr && minusc && *argptr)
-	        arg0 = *argptr++;
+	if (minusc != NULL) {
+		if (argptr == NULL || *argptr == NULL)
+			error("Bad -c option");
+		minusc = *argptr++;
+		if (*argptr != 0)
+			arg0 = *argptr++;
+	}
 
 	shellparam.p = argptr;
 	shellparam.reset = 1;
@@ -179,17 +184,7 @@
 		}
 		while ((c = *p++) != '\0') {
 			if (c == 'c' && cmdline) {
-				char *q;
-#ifdef NOHACK	/* removing this code allows sh -ce 'foo' for compat */
-				if (*p == '\0')
-#endif
-					q = *argptr++;
-				if (q == NULL || minusc != NULL)
-					error("Bad -c option");
-				minusc = q;
-#ifdef NOHACK
-				break;
-#endif
+				minusc = "";	/* command is after shell args*/
 			} else if (c == 'o') {
 				minus_o(*argptr, val);
 				if (*argptr)

-- 
David Laight: david@l8s.co.uk