From f5f215e2517285d16ecc014d1f59b37d1e2e420b Mon Sep 17 00:00:00 2001 From: Jilles Tjoelker Date: Fri, 17 Jun 2011 10:21:24 +0000 Subject: sh: Skip variables with invalid names in "set", "export -p", "readonly -p". This ensures the output of these commands is valid shell input. --- bin/sh/var.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'bin') 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(' '); } -- cgit v1.2.3