sh: Skip vars with invalid names in "set", "export -p", "readonly -p".
authorPeter Avalos <pavalos@dragonflybsd.org>
Sun, 21 Aug 2011 21:39:50 +0000 (14:39 -0700)
committerPeter Avalos <pavalos@dragonflybsd.org>
Sun, 21 Aug 2011 21:39:50 +0000 (14:39 -0700)
This ensures the output of these commands is valid shell input.

Obtained-from:   FreeBSD 223183

bin/sh/var.c
tools/regression/bin/sh/builtins/export1.0 [new file with mode: 0644]
tools/regression/bin/sh/builtins/set2.0 [new file with mode: 0644]

index c100e8b..a3a5a9b 100644 (file)
@@ -34,7 +34,7 @@
  * SUCH DAMAGE.
  *
  * @(#)var.c   8.3 (Berkeley) 5/4/95
- * $FreeBSD: src/bin/sh/var.c,v 1.62 2011/06/13 21:03:27 jilles Exp $
+ * $FreeBSD: src/bin/sh/var.c,v 1.63 2011/06/17 10:21:24 jilles Exp $
  */
 
 #include <unistd.h>
@@ -609,6 +609,12 @@ showvarscmd(int argc __unused, char **argv __unused)
 
        qsort(vars, n, sizeof(*vars), var_compare);
        for (i = 0; i < n; i++) {
+               /*
+                * Skip improper variable names so the output remains usable as
+                * shell input.
+                */
+               if (!isassignment(vars[i]))
+                       continue;
                s = strchr(vars[i], '=');
                s++;
                outbin(vars[i], s - vars[i], out1);
@@ -680,6 +686,13 @@ exportcmd(int argc, char **argv)
                        for (vp = *vpp ; vp ; vp = vp->next) {
                                if (vp->flags & flag) {
                                        if (values) {
+                                               /*
+                                                * Skip improper variable names
+                                                * so the output remains usable
+                                                * as shell input.
+                                                */
+                                               if (!isassignment(vp->text))
+                                                       continue;
                                                out1str(cmdname);
                                                out1c(' ');
                                        }
diff --git a/tools/regression/bin/sh/builtins/export1.0 b/tools/regression/bin/sh/builtins/export1.0
new file mode 100644 (file)
index 0000000..8315699
--- /dev/null
@@ -0,0 +1,3 @@
+# $FreeBSD: src/tools/regression/bin/sh/builtins/export1.0,v 1.1 2011/06/17 10:21:24 jilles Exp $
+
+env @badness=1 ${SH} -c 'v=`export -p`; eval "$v"'
diff --git a/tools/regression/bin/sh/builtins/set2.0 b/tools/regression/bin/sh/builtins/set2.0
new file mode 100644 (file)
index 0000000..c7cc5cc
--- /dev/null
@@ -0,0 +1,3 @@
+# $FreeBSD: src/tools/regression/bin/sh/builtins/set2.0,v 1.1 2011/06/17 10:21:24 jilles Exp $
+
+! env @badness=1 ${SH} -c 'v=`set`; eval "$v"' 2>&1 | grep @badness