[libcxx-commits] [libcxx] b8b23aa - [libcxx] [test] Quote env variables that are set with a shell "export" in ssh.py

Martin Storsjö via libcxx-commits libcxx-commits at lists.llvm.org
Thu Mar 25 00:53:51 PDT 2021


Author: Martin Storsjö
Date: 2021-03-25T09:46:44+02:00
New Revision: b8b23aa80eefe84187d6ba364d06496c90c53bdb

URL: https://github.com/llvm/llvm-project/commit/b8b23aa80eefe84187d6ba364d06496c90c53bdb
DIFF: https://github.com/llvm/llvm-project/commit/b8b23aa80eefe84187d6ba364d06496c90c53bdb.diff

LOG: [libcxx] [test] Quote env variables that are set with a shell "export" in ssh.py

This safeguards against cases if some of the env vars contain chars
that are problematic for shells, e.g. if called with --env "X=Y;Z".

(In cases of cross testing for windows, the PATH variable can end up
specified with semicolon separators - even if specifying a PATH when
cross testing in such differing environments might not make sense or
do anything - but this makes ssh.py not break on such a variable.)

Differential Revision: https://reviews.llvm.org/D99242

Added: 
    

Modified: 
    libcxx/utils/ssh.py

Removed: 
    


################################################################################
diff  --git a/libcxx/utils/ssh.py b/libcxx/utils/ssh.py
index a434271265a4c..d6346fcb20be9 100755
--- a/libcxx/utils/ssh.py
+++ b/libcxx/utils/ssh.py
@@ -23,6 +23,12 @@
 import tarfile
 import tempfile
 
+try:
+   from shlex import quote as cmd_quote
+except ImportError:
+   # for Python 2 compatibility
+   from pipes import quote as cmd_quote
+
 def ssh(args, command):
     cmd = ['ssh', '-oBatchMode=yes']
     if args.extra_ssh_args is not None:
@@ -107,7 +113,7 @@ def main():
         commandLine = (pathOnRemote(x) if isTestExe(x) else x for x in commandLine)
         remoteCommands.append('cd {}'.format(tmp))
         if args.env:
-            remoteCommands.append('export {}'.format(' '.join(args.env)))
+            remoteCommands.append('export {}'.format(cmd_quote(' '.join(args.env))))
         remoteCommands.append(subprocess.list2cmdline(commandLine))
 
         # Finally, SSH to the remote host and execute all the commands.


        


More information about the libcxx-commits mailing list