summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--src/expand.c4
-rw-r--r--src/parser.c7
3 files changed, 12 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 1db14ac..69ba464 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2007-10-08  Herbert Xu <herbert@gondor.apana.org.au>
+
+	* Report substition errors at expansion time.
+
 2007-10-06  Herbert Xu <herbert@gondor.apana.org.au>
 
 	* Add pushstackmark.
diff --git a/src/expand.c b/src/expand.c
index e3e5d8f..54fe908 100644
--- a/src/expand.c
+++ b/src/expand.c
@@ -749,6 +749,10 @@ evalvar(char *p, int flag)
 
 	varflags = *p++;
 	subtype = varflags & VSTYPE;
+
+	if (!subtype)
+		sh_error("Bad substitution");
+
 	quoted = flag & EXP_QUOTED;
 	var = p;
 	easy = (!quoted || (*var == '@' && shellparam.nparam));
diff --git a/src/parser.c b/src/parser.c
index d0e0553..4b8a5fe 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -1204,9 +1204,8 @@ varname:
 			USTPUTC(cc, out);
 		}
 		else
-badsub:			synerror("Bad substitution");
+			goto badsub;
 
-		STPUTC('=', out);
 		if (subtype == 0) {
 			switch (c) {
 			case ':':
@@ -1216,7 +1215,7 @@ badsub:			synerror("Bad substitution");
 			default:
 				p = strchr(types, c);
 				if (p == NULL)
-					goto badsub;
+					break;
 				subtype |= p - types + VSNORMAL;
 				break;
 			case '%':
@@ -1234,6 +1233,7 @@ badsub:			synerror("Bad substitution");
 				}
 			}
 		} else {
+badsub:
 			pungetc();
 		}
 		*((char *)stackblock() + typeloc) = subtype;
@@ -1242,6 +1242,7 @@ badsub:			synerror("Bad substitution");
 			if (dblquote)
 				dqvarnest++;
 		}
+		STPUTC('=', out);
 	}
 	goto parsesub_return;
 }