1
0
mirror of https://github.com/gryf/wicd.git synced 2025-12-21 13:28:08 +01:00

properly escape characters in script parameters

This commit is contained in:
Adam Blackburn
2009-08-13 05:05:44 -05:00
parent 6e3d6c8d02
commit 078e47a110

View File

@@ -31,6 +31,7 @@ from threading import Thread
from subprocess import Popen, STDOUT, PIPE, call from subprocess import Popen, STDOUT, PIPE, call
from commands import getoutput from commands import getoutput
from itertools import repeat, chain, izip from itertools import repeat, chain, izip
from pipes import quote
# wicd imports # wicd imports
import wpath import wpath
@@ -192,13 +193,13 @@ def ExecuteScripts(scripts_dir, verbose=False, extra_parameters=()):
def ExecuteScript(script, verbose=False, extra_parameters=()): def ExecuteScript(script, verbose=False, extra_parameters=()):
""" Execute a command and send its output to the bit bucket. """ """ Execute a command and send its output to the bit bucket. """
extra_parameters = [ quote(s) for s in extra_parameters ]
params = ' '.join(extra_parameters)
# escape script name
script = quote(script)
if verbose: if verbose:
print "Executing %s with params %s" % (script, ' '.join(extra_parameters)) print "Executing %s with params %s" % (script, params)
extra_parameters = [ s.replace('"', '\\"') for s in extra_parameters ] ret = call('%s %s > /dev/null 2>&1' % (script, params), shell=True)
# escape characters
params = '" "'.join(extra_parameters)
script = script.replace(' ', '\\ ')
ret = call('%s "%s" > /dev/null 2>&1' % (script, params), shell=True)
if verbose: if verbose:
print "%s returned %s" % (script, ret) print "%s returned %s" % (script, ret)