From: Eric Ball Date: Fri, 20 Mar 2020 23:26:47 +0000 (-0700) Subject: Fix potential symlink loop in _compress_text() X-Git-Tag: v0.32.0~3^2 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F74%2F63474%2F1;p=releng%2Flftools.git Fix potential symlink loop in _compress_text() By checking if os.path.exists can find the path, we stop the method from attempting to traverse symlinked directories. This also pins a more recent version of pre-commit, as the older version was making a pre-commit file with errors. Issue: RELENG-2576 Change-Id: I2265c9895444892877f684b807287ebe8319083a Signed-off-by: Eric Ball --- diff --git a/lftools/deploy.py b/lftools/deploy.py index 70b91022..fa6bd362 100755 --- a/lftools/deploy.py +++ b/lftools/deploy.py @@ -50,9 +50,14 @@ def _compress_text(dir): paths.extend(glob.glob(search, recursive=True)) for _file in paths: - with open(_file, "rb") as src, gzip.open("{}.gz".format(_file), "wb") as dest: - shutil.copyfileobj(src, dest) - os.remove(_file) + # glob may follow symlink paths that open can't find + if os.path.exists(_file): + log.debug("Compressing file {}".format(_file)) + with open(_file, "rb") as src, gzip.open("{}.gz".format(_file), "wb") as dest: + shutil.copyfileobj(src, dest) + os.remove(_file) + else: + log.info("Could not open path from glob {}".format(_file)) os.chdir(save_dir) diff --git a/requirements.txt b/requirements.txt index 8617a306..b1343a6f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -23,7 +23,7 @@ multi-key-dict==2.0.3 nodeenv==1.3.5 oauth2client==4.1.3 pbr==5.4.4 -pre-commit==1.21.0 +pre-commit~=2.2.0 pyasn1==0.4.8 pyasn1-modules==0.2.8 pygerrit2==2.0.10