aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorGravatar diamondm <diamondm@google.com>2018-05-24 12:58:37 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-05-24 12:59:44 -0700
commit2732b176361d04a0aae6f651568a55a119c52afd (patch)
tree367f5f46dd29a3708be44b3b4bffdfa78e06f822 /tools
parentd3d05b2ad55f89f77832880e1088fc472dae1b81 (diff)
Use pipes.quote() rather than manual quoting, and do so consistently wherever shell=True is set.
RELNOTES: None PiperOrigin-RevId: 197939143
Diffstat (limited to 'tools')
-rwxr-xr-xtools/objc/j2objc_dead_code_pruner.py33
1 files changed, 17 insertions, 16 deletions
diff --git a/tools/objc/j2objc_dead_code_pruner.py b/tools/objc/j2objc_dead_code_pruner.py
index 4f22259944..da42862464 100755
--- a/tools/objc/j2objc_dead_code_pruner.py
+++ b/tools/objc/j2objc_dead_code_pruner.py
@@ -29,6 +29,7 @@ import argparse
from collections import OrderedDict
import multiprocessing
import os
+import pipes # swap to shlex once on Python 3
import Queue
import re
import shutil
@@ -312,8 +313,8 @@ def MatchObjectNamesInArchive(xcrunwrapper, archive, object_names):
Returns:
A list of basenames of matching members of the given archive
"""
- ar_contents_cmd = '%s ar -t %s' % (xcrunwrapper, archive)
- real_object_names = subprocess.check_output(ar_contents_cmd, shell=True)
+ ar_contents_cmd = [xcrunwrapper, 'ar', '-t', archive]
+ real_object_names = subprocess.check_output(ar_contents_cmd)
expected_object_name_regex = r'^(?:%s)(?:_[0-9a-f]{32}(?:-[0-9]+)?)?\.o$' % (
'|'.join([re.escape(name) for name in object_names]))
return re.findall(expected_object_name_regex, real_object_names,
@@ -367,35 +368,35 @@ def PruneArchiveFile(input_archive, output_archive, dummy_archive,
# If all objects in the archive are unreachable, just copy over a dummy
# archive that contains no object
if len(unreachable_object_names) == len(source_files):
- j2objc_cmd = 'cp %s %s' % (dummy_archive, output_archive)
+ j2objc_cmd = 'cp %s %s' % (pipes.quote(dummy_archive),
+ pipes.quote(output_archive))
# Else we need to prune the archive of unreachable objects
else:
cmd_env['ZERO_AR_DATE'] = '1'
# Copy the input archive to the output location
- j2objc_cmd += 'cp %s %s && ' % (input_archive, output_archive)
+ j2objc_cmd += 'cp %s %s && ' % (pipes.quote(input_archive),
+ pipes.quote(output_archive))
# Make the output archive editable
- j2objc_cmd += 'chmod +w %s && ' % (output_archive)
+ j2objc_cmd += 'chmod +w %s && ' % (pipes.quote(output_archive))
# Remove the unreachable objects from the archive
unreachable_object_names = MatchObjectNamesInArchive(
xcrunwrapper, input_archive, unreachable_object_names)
- # We need to quote the object names because they may contains special
- # shell characters.
- quoted_unreachable_object_names = [
- "'" + unreachable_object_name + "'"
- for unreachable_object_name in unreachable_object_names]
j2objc_cmd += '%s ar -d -s %s %s && ' % (
- xcrunwrapper,
- output_archive,
- ' '.join(quoted_unreachable_object_names))
+ pipes.quote(xcrunwrapper),
+ pipes.quote(output_archive),
+ ' '.join(pipes.quote(uon) for uon in unreachable_object_names))
# Update the table of content of the archive file
- j2objc_cmd += '%s ranlib %s' % (xcrunwrapper, output_archive)
+ j2objc_cmd += '%s ranlib %s' % (pipes.quote(xcrunwrapper),
+ pipes.quote(output_archive))
# There are no unreachable objects, we just copy over the original archive
else:
- j2objc_cmd = 'cp %s %s' % (input_archive, output_archive)
+ j2objc_cmd = 'cp %s %s' % (pipes.quote(input_archive),
+ pipes.quote(output_archive))
# The archive cannot be pruned by J2ObjC dead code removal, just copy over
# the original archive
else:
- j2objc_cmd = 'cp %s %s' % (input_archive, output_archive)
+ j2objc_cmd = 'cp %s %s' % (pipes.quote(input_archive),
+ pipes.quote(output_archive))
subprocess.check_output(
j2objc_cmd, stderr=subprocess.STDOUT, shell=True, env=cmd_env)