Commit d8b103b8 authored by Benjamin Peterson's avatar Benjamin Peterson Committed by GitHub

closes bpo-34540: Convert shutil._call_external_zip to use subprocess rather...

closes bpo-34540: Convert shutil._call_external_zip to use subprocess rather than distutils.spawn. (GH-8985)
parent 491740f1
...@@ -413,17 +413,21 @@ def _make_tarball(base_name, base_dir, compress="gzip", verbose=0, dry_run=0, ...@@ -413,17 +413,21 @@ def _make_tarball(base_name, base_dir, compress="gzip", verbose=0, dry_run=0,
return archive_name return archive_name
def _call_external_zip(base_dir, zip_filename, verbose=False, dry_run=False): def _call_external_zip(base_dir, zip_filename, verbose, dry_run, logger):
# XXX see if we want to keep an external call here # XXX see if we want to keep an external call here
if verbose: if verbose:
zipoptions = "-r" zipoptions = "-r"
else: else:
zipoptions = "-rq" zipoptions = "-rq"
from distutils.errors import DistutilsExecError cmd = ["zip", zipoptions, zip_filename, base_dir]
from distutils.spawn import spawn if logger is not None:
logger.info(' '.join(cmd))
if dry_run:
return
import subprocess
try: try:
spawn(["zip", zipoptions, zip_filename, base_dir], dry_run=dry_run) subprocess.check_call(cmd)
except DistutilsExecError: except subprocess.CalledProcessError:
# XXX really should distinguish between "couldn't find # XXX really should distinguish between "couldn't find
# external 'zip' command" and "zip failed". # external 'zip' command" and "zip failed".
raise ExecError, \ raise ExecError, \
...@@ -458,7 +462,7 @@ def _make_zipfile(base_name, base_dir, verbose=0, dry_run=0, logger=None): ...@@ -458,7 +462,7 @@ def _make_zipfile(base_name, base_dir, verbose=0, dry_run=0, logger=None):
zipfile = None zipfile = None
if zipfile is None: if zipfile is None:
_call_external_zip(base_dir, zip_filename, verbose, dry_run) _call_external_zip(base_dir, zip_filename, verbose, dry_run, logger)
else: else:
if logger is not None: if logger is not None:
logger.info("creating '%s' and adding '%s' to it", logger.info("creating '%s' and adding '%s' to it",
......
When ``shutil.make_archive`` falls back to the external ``zip`` problem, it
uses :mod:`subprocess` to invoke it rather than :mod:`distutils.spawn`. This
closes a possible shell injection vector.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment