sh: Skip variables with invalid names in "set", "export -p", "readonly -p".

This ensures the output of these commands is valid shell input.
This commit is contained in:
Jilles Tjoelker 2011-06-17 10:21:24 +00:00
parent e0607dec4d
commit f5f215e251
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=223183
3 changed files with 19 additions and 0 deletions

View File

@ -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(' ');
}

View File

@ -0,0 +1,3 @@
# $FreeBSD$
env @badness=1 ${SH} -c 'v=`export -p`; eval "$v"'

View File

@ -0,0 +1,3 @@
# $FreeBSD$
! env @badness=1 ${SH} -c 'v=`set`; eval "$v"' 2>&1 | grep @badness