Skip to content
This repository was archived by the owner on Mar 3, 2023. It is now read-only.
This repository was archived by the owner on Mar 3, 2023. It is now read-only.

getEnvFromShell() does not handle newlines in environment variables correctly #17627

@brettle

Description

@brettle

Prerequisites

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

  1. Add this to the end of ~/.bashrc: export atom_test=$'foo\nbar'
  2. Launch atom from the desktop (not from a shell)
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions