Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.7] closes bpo-34540: Convert shutil._call_external_zip to use subprocess rather than distutils.spawn. #8985

Merged
merged 1 commit into from Aug 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
closes bpo-34540: Convert shutil._call_external_zip to use subprocess…
… rather than distutils.spawn.
  • Loading branch information
benjaminp committed Aug 29, 2018
commit add531a1e55b0a739b0f42582f1c9747e5649ace
16 changes: 10 additions & 6 deletions Lib/shutil.py
Expand Up @@ -413,17 +413,21 @@ def _set_uid_gid(tarinfo):

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
if verbose:
zipoptions = "-r"
else:
zipoptions = "-rq"
from distutils.errors import DistutilsExecError
from distutils.spawn import spawn
cmd = ["zip", zipoptions, zip_filename, base_dir]
if logger is not None:
logger.info(' '.join(cmd))
if dry_run:
return
import subprocess
try:
spawn(["zip", zipoptions, zip_filename, base_dir], dry_run=dry_run)
except DistutilsExecError:
subprocess.check_call(cmd)
except subprocess.CalledProcessError:
# XXX really should distinguish between "couldn't find
# external 'zip' command" and "zip failed".
raise ExecError, \
Expand Down Expand Up @@ -458,7 +462,7 @@ def _make_zipfile(base_name, base_dir, verbose=0, dry_run=0, logger=None):
zipfile = 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:
if logger is not None:
logger.info("creating '%s' and adding '%s' to it",
Expand Down
@@ -0,0 +1,3 @@
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.