summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2011-05-04 21:49:34 +0000
committerjilles <jilles@FreeBSD.org>2011-05-04 21:49:34 +0000
commitfa0f3c42ef6452770ad1eaf8d50f9b2e7af7fb88 (patch)
treea70b358bc2039c03fc15cbaeaba4323d4cbd34d9
parent0cc27c3d6b2a3daf9dd8312fbbe87f86d0d55ce7 (diff)
downloadFreeBSD-src-fa0f3c42ef6452770ad1eaf8d50f9b2e7af7fb88.zip
FreeBSD-src-fa0f3c42ef6452770ad1eaf8d50f9b2e7af7fb88.tar.gz
sh: Detect an error for ${#var<GARBAGE>}.
In particular, this makes things like ${#foo[0]} and ${#foo[@]} errors rather than silent equivalents of ${#foo}. PR: bin/151720 Submitted by: Mark Johnston Exp-run done by: pav (with some other sh(1) changes)
-rw-r--r--bin/sh/parser.c2
-rw-r--r--tools/regression/bin/sh/errors/bad-parm-exp6.22
-rw-r--r--tools/regression/bin/sh/errors/bad-parm-exp6.2.stderr1
3 files changed, 5 insertions, 0 deletions
diff --git a/bin/sh/parser.c b/bin/sh/parser.c
index c4191b4..43822f9 100644
--- a/bin/sh/parser.c
+++ b/bin/sh/parser.c
@@ -1569,6 +1569,8 @@ varname:
}
}
} else if (subtype != VSERROR) {
+ if (subtype == VSLENGTH && c != '}')
+ subtype = VSERROR;
pungetc();
}
STPUTC('=', out);
diff --git a/tools/regression/bin/sh/errors/bad-parm-exp6.2 b/tools/regression/bin/sh/errors/bad-parm-exp6.2
new file mode 100644
index 0000000..ba51442
--- /dev/null
+++ b/tools/regression/bin/sh/errors/bad-parm-exp6.2
@@ -0,0 +1,2 @@
+# $FreeBSD$
+${#foo^}
diff --git a/tools/regression/bin/sh/errors/bad-parm-exp6.2.stderr b/tools/regression/bin/sh/errors/bad-parm-exp6.2.stderr
new file mode 100644
index 0000000..dbf14b5
--- /dev/null
+++ b/tools/regression/bin/sh/errors/bad-parm-exp6.2.stderr
@@ -0,0 +1 @@
+./errors/bad-parm-exp6.2: ${foo...}: Bad substitution
OpenPOWER on IntegriCloud