dash command variable assignments remain in the shell after command execution completed
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
dash (Ubuntu) |
Confirmed
|
Undecided
|
Unassigned |
Bug Description
If a shell function is invoked with variable assignments preceding it, the assignments remain in the shell after the command execution completed. This is unexpected behavior and might be a potential security issue, since it allows to modify the user environment in a subtle unexpected way. For example, consider the following commands that shouldn't change the SHELL value outside function foo, yet it does in Ubuntu 14.04
echo $SHELL # check our default shell, gives /bin/bash
foo () { printenv | grep SHELL; } # no side effects, can be anything
SHELL=/bin/sh foo
echo $SHELL # now gives /bin/sh, but expected to give /bin/bash as before
I checked bash and zsh, none of them have this problem. sh in freebsd and debian handle this case correctly. So far, it seems the issue is limited to Ubuntu dash.
lsb_release -rd
Description: Ubuntu 14.04.3 LTS
Release: 14.04
apt-cache policy dash
dash:
Installed: 0.5.7-4ubuntu1
Candidate: 0.5.7-4ubuntu1
Version table:
*** 0.5.7-4ubuntu1 0
500 http://
100 /var/lib/
Changed in dash (Ubuntu): | |
status: | New → Opinion |
information type: | Private Security → Public Security |
Changed in dash (Ubuntu): | |
status: | New → Confirmed |
I found that POSIX allows this, so I changed the status to opinion
"If no command name results, or if the command name is a special built-in or function, variable assignments shall affect the current execution environment." pubs.opengroup. org/onlinepubs/ 9699919799/
http://
I still think it would be better to keep those assignments local to the function as other shell do. As it stands, it is not immediately obvious from looking at the command line if those assignments will affect or not affect the current execution environment. Wrapping some command into a shell function, changes semantics of how those assignments are handled to the opposite without any visible changes to the command line.