summaryrefslogtreecommitdiffstats
path: root/bin/sh/var.c
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2011-06-17 10:21:24 +0000
committerjilles <jilles@FreeBSD.org>2011-06-17 10:21:24 +0000
commitf84ee4a43b5388f4afb06538be8e54070085873e (patch)
treebb3bbdf23bd54d1e810d6fea0f2ca174c21f5530 /bin/sh/var.c
parent108671f8107f11abb39794484ddd7f68d4f1991d (diff)
downloadFreeBSD-src-f84ee4a43b5388f4afb06538be8e54070085873e.zip
FreeBSD-src-f84ee4a43b5388f4afb06538be8e54070085873e.tar.gz
sh: Skip variables with invalid names in "set", "export -p", "readonly -p".
This ensures the output of these commands is valid shell input.
Diffstat (limited to 'bin/sh/var.c')
-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 d5b2522..b3bc6f7f 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(' ');
}
OpenPOWER on IntegriCloud