diff options
author | Brian May <brian@linuxpenguins.xyz> | 2016-03-16 16:37:26 +1100 |
---|---|---|
committer | Brian May <brian@linuxpenguins.xyz> | 2016-03-16 16:38:22 +1100 |
commit | 3541e4bdfe1970000e00e27a037f2884cb15df58 (patch) | |
tree | dcca584d642558024509f4a7e240c66e068f4ed9 | |
parent | efdb9b8f9468e4778ca1ae34509a5bf9315da66f (diff) |
Fix shell quoting
Due to nested shells, we need to have multiple layers of quoting. Yuck.
Closes #80
-rw-r--r-- | sshuttle/ssh.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/sshuttle/ssh.py b/sshuttle/ssh.py index 1633b2e..cc89c0d 100644 --- a/sshuttle/ssh.py +++ b/sshuttle/ssh.py @@ -8,6 +8,12 @@ import subprocess as ssubprocess import sshuttle.helpers as helpers from sshuttle.helpers import debug2 +try: + # Python >= 3.5 + from shlex import quote +except ImportError: + # Python 2.x + from pipes import quote def readfile(name): tokens = name.split(".") @@ -108,8 +114,9 @@ def connect(ssh_cmd, rhostport, python, stderr, options): if python: pycmd = "'%s' -c '%s'" % (python, pyscript) else: - pycmd = ("exec /bin/sh -c \'P=python3.5; $P -V 2>/dev/null || P=python; " - "exec \"$P\" -c \\'%s\\'\'") % pyscript + pycmd = ("P=python3.5; $P -V 2>/dev/null || P=python; " + "exec \"$P\" -c %s") % quote(pyscript) + pycmd = ("exec /bin/sh -c %s" % quote(pycmd)) argv = (sshl + portl + [rhost, '--', pycmd]) |