mirror of
https://github.com/opnsense/src.git
synced 2026-06-09 00:32:25 -04:00
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:
parent
e0607dec4d
commit
f5f215e251
3 changed files with 19 additions and 0 deletions
13
bin/sh/var.c
13
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(' ');
|
||||
}
|
||||
|
|
|
|||
3
tools/regression/bin/sh/builtins/export1.0
Normal file
3
tools/regression/bin/sh/builtins/export1.0
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# $FreeBSD$
|
||||
|
||||
env @badness=1 ${SH} -c 'v=`export -p`; eval "$v"'
|
||||
3
tools/regression/bin/sh/builtins/set2.0
Normal file
3
tools/regression/bin/sh/builtins/set2.0
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# $FreeBSD$
|
||||
|
||||
! env @badness=1 ${SH} -c 'v=`set`; eval "$v"' 2>&1 | grep @badness
|
||||
Loading…
Reference in a new issue