Skip to content

Commit

Permalink
Ensure locale is set to C for external commands
Browse files Browse the repository at this point in the history
Otherwise the output can vary and confuse our attempts to parse it.

Fixes: 93
  • Loading branch information
brianmay committed Apr 23, 2016
1 parent 1dda9dd commit 8fad282
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
13 changes: 11 additions & 2 deletions sshuttle/linux.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import socket
import subprocess as ssubprocess
from sshuttle.helpers import log, debug1, Fatal, family_to_string
Expand All @@ -18,7 +19,11 @@ def ipt_chain_exists(family, table, name):
else:
raise Exception('Unsupported family "%s"' % family_to_string(family))
argv = [cmd, '-t', table, '-nL']
p = ssubprocess.Popen(argv, stdout=ssubprocess.PIPE)
env = {
'PATH': os.environ['PATH'],
'LC_ALL': "C",
}
p = ssubprocess.Popen(argv, stdout=ssubprocess.PIPE, env=env)
for line in p.stdout:
if line.startswith(b'Chain %s ' % name.encode("ASCII")):
return True
Expand All @@ -35,7 +40,11 @@ def ipt(family, table, *args):
else:
raise Exception('Unsupported family "%s"' % family_to_string(family))
debug1('>> %s\n' % ' '.join(argv))
rv = ssubprocess.call(argv)
env = {
'PATH': os.environ['PATH'],
'LC_ALL': "C",
}
rv = ssubprocess.call(argv, env=env)
if rv:
raise Fatal('%r returned %d' % (argv, rv))

Expand Down
7 changes: 6 additions & 1 deletion sshuttle/methods/pf.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,14 @@ def pfctl(args, stdin=None):
argv = ['pfctl'] + list(args.split(" "))
debug1('>> %s\n' % ' '.join(argv))

env = {
'PATH': os.environ['PATH'],
'LC_ALL': "C",
}
p = ssubprocess.Popen(argv, stdin=ssubprocess.PIPE,
stdout=ssubprocess.PIPE,
stderr=ssubprocess.PIPE)
stderr=ssubprocess.PIPE,
env=env)
o = p.communicate(stdin)
if p.returncode:
raise Fatal('%r returned %d' % (argv, p.returncode))
Expand Down
6 changes: 5 additions & 1 deletion sshuttle/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ def _shl(n, bits):
def _list_routes():
# FIXME: IPv4 only
argv = ['netstat', '-rn']
p = ssubprocess.Popen(argv, stdout=ssubprocess.PIPE)
env = {
'PATH': os.environ['PATH'],
'LC_ALL': "C",
}
p = ssubprocess.Popen(argv, stdout=ssubprocess.PIPE, env=env)
routes = []
for line in p.stdout:
cols = re.split(r'\s+', line.decode("ASCII"))
Expand Down

0 comments on commit 8fad282

Please sign in to comment.