aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorJilles Tjoelker <jilles@FreeBSD.org>2011-06-17 10:21:24 +0000
committerJilles Tjoelker <jilles@FreeBSD.org>2011-06-17 10:21:24 +0000
commitf5f215e2517285d16ecc014d1f59b37d1e2e420b (patch)
treebb3bbdf23bd54d1e810d6fea0f2ca174c21f5530 /bin
parente0607dec4d18f7ccfe2eb425fe5f7e56ece9e9d1 (diff)
downloadsrc-f5f215e2517285d16ecc014d1f59b37d1e2e420b.tar.gz
src-f5f215e2517285d16ecc014d1f59b37d1e2e420b.zip
sh: Skip variables with invalid names in "set", "export -p", "readonly -p".
This ensures the output of these commands is valid shell input.
Notes
Notes: svn path=/head/; revision=223183
Diffstat (limited to 'bin')
-rw-r--r--bin/sh/var.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/bin/sh/var.c b/bin/sh/var.c
index d5b252230cb0..b3bc6f7fdf8f 100644
--- a/bin/sh/var.c
+++ b/bin/sh/var.c
@@ -612,6 +612,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);
@@ -683,6 +689,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(' ');
}