This commit is contained in:
Kovid Goyal 2022-03-08 23:05:42 +05:30
parent 0661caf9da
commit 2341a27f63
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -406,19 +406,19 @@ def get_remote_command(
# login shell with -c. If the user has a non POSIX login shell it might # login shell with -c. If the user has a non POSIX login shell it might
# have different escaping semantics and syntax, so the command it should # have different escaping semantics and syntax, so the command it should
# execute has to be as simple as possible, basically of the form # execute has to be as simple as possible, basically of the form
# interpreter -c wrapper_cmd escaped_bootstrap_script # interpreter -c unwrap_script escaped_bootstrap_script
# The wrapper_cmd is responsible for unescaping the bootstrap script and # The unwrap_script is responsible for unescaping the bootstrap script and
# executing it. # executing it.
if is_python: if is_python:
es = standard_b64encode(sh_script.encode('utf-8')).decode('ascii') es = standard_b64encode(sh_script.encode('utf-8')).decode('ascii')
wrapper_cmd = '''"import base64, sys; eval(compile(base64.standard_b64decode(sys.argv[-1]), 'bootstrap.py', 'exec'))"''' unwrap_script = '''"import base64, sys; eval(compile(base64.standard_b64decode(sys.argv[-1]), 'bootstrap.py', 'exec'))"'''
else: else:
# We cant rely on base64 being available on the remote system, so instead # We cant rely on base64 being available on the remote system, so instead
# we quote the bootstrap script by replacing ' and \ with \v and \f and # we quote the bootstrap script by replacing ' and \ with \v and \f and
# surrounding with ' # surrounding with '
es = "'" + sh_script.replace("'", '\v').replace('\\', '\f') + "'" es = "'" + sh_script.replace("'", '\v').replace('\\', '\f') + "'"
wrapper_cmd = r"""'eval "$(echo "$0" | tr \\\v\\\f \\\047\\\134)"' """ unwrap_script = r"""'eval "$(echo "$0" | tr \\\v\\\f \\\047\\\134)"' """
return [interpreter, '-c', wrapper_cmd, es] return [interpreter, '-c', unwrap_script, es]
def main(args: List[str]) -> NoReturn: def main(args: List[str]) -> NoReturn: