-
Notifications
You must be signed in to change notification settings - Fork 17.3k
getEnvFromShell() does not handle newlines in environment variables correctly #17627
Description
Prerequisites
- Put an X between the brackets on this line if you have done all of the following:
- Reproduced the problem in Safe Mode: https://flight-manual.atom.io/hacking-atom/sections/debugging/#using-safe-mode
- Followed all applicable steps in the debugging guide: https://flight-manual.atom.io/hacking-atom/sections/debugging/
- Checked the FAQs on the message board for common solutions: https://discuss.atom.io/c/faq
- Checked that your issue isn't already filed: https://github.com/issues?utf8=✓&q=is%3Aissue+user%3Aatom
- Checked that there is not already an Atom package that provides the described functionality: https://atom.io/packages
Description
If the user has an environment variable that contains newlines when atom is launched (other than from the command-line), then that environment variable will not be correctly passed to subprocesses. Environment variables containing newlines commonly occur when bash functions are exported.
Steps to Reproduce
- Add this to the end of ~/.bashrc:
export atom_test=$'foo\nbar' - Launch atom from the desktop (not from a shell)
- Inspect the value of
process.env['atom_test']
Expected behavior:
The value should be:
foo
bar
Actual behavior: [What actually happens]
The value is:
foo
Reproduces how often:
100% of the time
Versions
[brettle@localhost tmp]$ atom --version
Atom : 1.28.0
Electron: 2.0.3
Chrome : 61.0.3163.100
Node : 8.9.3
[brettle@localhost tmp]$ apm --version
apm 1.19.0
npm 3.10.10
node 6.9.5 x64
atom 1.28.0
python 2.7.15
git 2.17.1
[brettle@localhost tmp]$ uname -a
Linux localhost.localdomain 4.17.3-200.fc28.x86_64 #1 SMP Tue Jun 26 14:17:07 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
[brettle@localhost tmp]$ rpm -q fedora-release
fedora-release-28-2.noarch
Additional Information
The essence of the problem is at this line in update-process-env.js. It is using newlines to split the result of executing
command env
within the user's shell at this line
Instead, I recommend using \0 to split the result of executing
command awk 'BEGIN{for(v in ENVIRON) printf("%s=%s\0", v, ENVIRON[v])}'
within the user's shell. This would address newlines in the variable values and the extremely rare case of newlines in the variable names.