Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spaces in environment variables lead to ProcessExecutionError #456

Closed
gsimbr opened this issue Jul 29, 2019 · 1 comment
Closed

Spaces in environment variables lead to ProcessExecutionError #456

gsimbr opened this issue Jul 29, 2019 · 1 comment

Comments

@gsimbr
Copy link
Contributor

gsimbr commented Jul 29, 2019

When using environment variables with spaces, the remote machines are unable to execute any command given.

The problem can e.g. reproduced when adapting the unit tests in test_remote.py:

class BaseRemoteMachineTest(object):
    def test_env(self):
        with self._connect() as rem:
            with pytest.raises(ProcessExecutionError):
              rem.python("-c", "import os;os.environ['FOOBAR72']")
            with rem.env(FOOBAR72 = "la la"):
                with rem.env(FOOBAR72 = "baba"):
                    out = rem.python("-c", "import os;print(os.environ['FOOBAR72'])")
                    assert out.strip() == "baba"
                out = rem.python("-c", "import os;print(os.environ['FOOBAR72'])")
                assert out.strip() == "la la"

where I added a space in the "lala" string, which yields

E               plumbum.commands.processes.ProcessExecutionError: Command line: ['cd', '/home/user', '&&', 'env', 'FOOBAR72=la la', '/usr/bin/python', '-c', '"import os;print(os.environ[\'FOOBAR72\'])"']
E               Exit code: 127
E               Stderr:  | env: ‘la’: No such file or directory

The usecase where we stumbled upon this problem was when using the environment variable LDFLAGS="-Wl,-O2 -Wl,--sort-common", which yielded a ProcessExecutionError with any given command:

E               Exit code: 127
E               Stderr:  | env: -Wl,--sort-common: No such file or directory

This is unexpected behaviour and should ideally be fixed by the library by performing appropriate escaping or at least add an earlier check that this is not supported.

@gsimbr
Copy link
Contributor Author

gsimbr commented Jul 29, 2019

I should add I've been using plumbum 1.6.7., 1.6.6 is also affected.

gsimbr added a commit to gsimbr/plumbum that referenced this issue Aug 1, 2019
* For ParamikoMachine and SshMachine, shell escape
  environment variables in order to not run into
  ProcessExecutionErrors when using environment
  variables with spaces and special characters
gsimbr added a commit to gsimbr/plumbum that referenced this issue Aug 1, 2019
* For ParamikoMachine and SshMachine, shell escape
  environment variables in order to not run into
  ProcessExecutionErrors when using environment
  variables with spaces and special characters
henryiii pushed a commit that referenced this issue Aug 1, 2019
* Refactor implementation for shell escaping

* Use Shquote from the standard library as of python3.3,
  fallback to legacy implementation in older versions.

* Improve shell-escaping of env variables (#456)

* For ParamikoMachine and SshMachine, shell escape
  environment variables in order to not run into
  ProcessExecutionErrors when using environment
  variables with spaces and special characters

* Add test for env variables with special chars
@gsimbr gsimbr closed this as completed Aug 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant