sh: Detect an error for ${#var<GARBAGE>}.
authorPeter Avalos <pavalos@dragonflybsd.org>
Sun, 3 Jul 2011 00:03:42 +0000 (14:03 -1000)
committerPeter Avalos <pavalos@dragonflybsd.org>
Sun, 21 Aug 2011 19:10:24 +0000 (12:10 -0700)
In particular, this makes things like ${#foo[0]} and ${#foo[@]} errors
rather than silent equivalents of ${#foo}.

Obtained-from:   FreeBSD SVN rev 221461

bin/sh/parser.c
tools/regression/bin/sh/errors/bad-parm-exp6.2 [new file with mode: 0644]
tools/regression/bin/sh/errors/bad-parm-exp6.2.stderr [new file with mode: 0644]

index 952dcd3..7c7a2bf 100644 (file)
@@ -34,7 +34,7 @@
  * SUCH DAMAGE.
  *
  * @(#)parser.c        8.7 (Berkeley) 5/16/95
- * $FreeBSD: src/bin/sh/parser.c,v 1.107 2011/04/20 22:24:54 jilles Exp $
+ * $FreeBSD: src/bin/sh/parser.c,v 1.108 2011/05/04 21:49:34 jilles Exp $
  */
 
 #include <stdio.h>
@@ -1568,6 +1568,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 (file)
index 0000000..e214a4a
--- /dev/null
@@ -0,0 +1,2 @@
+# $FreeBSD: src/tools/regression/bin/sh/errors/bad-parm-exp6.2,v 1.1 2011/05/04 21:49:34 jilles Exp $
+${#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 (file)
index 0000000..dbf14b5
--- /dev/null
@@ -0,0 +1 @@
+./errors/bad-parm-exp6.2: ${foo...}: Bad substitution