mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 772595 - Better escape commands sent to devicemanager shell;r=jmaher
This commit is contained in:
parent
fd7f652fe8
commit
2da8fac0b6
@ -509,7 +509,28 @@ class DeviceManager:
|
||||
success: True
|
||||
failure: False
|
||||
"""
|
||||
|
||||
|
||||
@staticmethod
|
||||
def _escapedCommandLine(cmd):
|
||||
""" Utility function to return escaped and quoted version of command line """
|
||||
quotedCmd = []
|
||||
|
||||
for arg in cmd:
|
||||
arg.replace('&', '\&')
|
||||
|
||||
needsQuoting = False
|
||||
for char in [ ' ', '(', ')', '"', '&' ]:
|
||||
if arg.find(char) >= 0:
|
||||
needsQuoting = True
|
||||
break
|
||||
if needsQuoting:
|
||||
arg = '\'%s\'' % arg
|
||||
|
||||
quotedCmd.append(arg)
|
||||
|
||||
return " ".join(quotedCmd)
|
||||
|
||||
|
||||
class NetworkTools:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
@ -95,24 +95,13 @@ class DeviceManagerADB(DeviceManager):
|
||||
# success: <return code>
|
||||
# failure: None
|
||||
def shell(self, cmd, outputfile, env=None, cwd=None):
|
||||
# need to quote and escape special characters here
|
||||
for (index, arg) in enumerate(cmd):
|
||||
arg.replace('&', '\&')
|
||||
|
||||
needsQuoting = False
|
||||
for char in [ ' ', '(', ')', '"', '&' ]:
|
||||
if arg.find(char):
|
||||
needsQuoting = True
|
||||
break
|
||||
if needsQuoting:
|
||||
cmd[index] = '\'%s\'' % arg
|
||||
|
||||
# This is more complex than you'd think because adb doesn't actually
|
||||
# return the return code from a process, so we have to capture the output
|
||||
# to get it
|
||||
# FIXME: this function buffers all output of the command into memory,
|
||||
# always. :(
|
||||
cmdline = " ".join(cmd) + "; echo $?"
|
||||
|
||||
# Getting the return code is more complex than you'd think because adb
|
||||
# doesn't actually return the return code from a process, so we have to
|
||||
# capture the output to get it
|
||||
cmdline = "%s; echo $?" % self._escapedCommandLine(cmd)
|
||||
|
||||
# prepend cwd and env to command if necessary
|
||||
if cwd:
|
||||
|
@ -260,7 +260,7 @@ class DeviceManagerSUT(DeviceManager):
|
||||
# success: <return code>
|
||||
# failure: None
|
||||
def shell(self, cmd, outputfile, env=None, cwd=None):
|
||||
cmdline = subprocess.list2cmdline(cmd)
|
||||
cmdline = self._escapedCommandLine(cmd)
|
||||
if env:
|
||||
cmdline = '%s %s' % (self.formatEnvString(env), cmdline)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user