[PATCH] D59236: Fix git-llvm crashing when trying to remove directory while cleaning
Raphael Isemann via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 12 00:07:03 PDT 2019
teemperor updated this revision to Diff 190212.
teemperor added a comment.
- Added safety check that we don't delete directories or files outside the llvm staging dir.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D59236/new/
https://reviews.llvm.org/D59236
Files:
llvm/utils/git-svn/git-llvm
Index: llvm/utils/git-svn/git-llvm
===================================================================
--- llvm/utils/git-svn/git-llvm
+++ llvm/utils/git-svn/git-llvm
@@ -22,6 +22,7 @@
import errno
import os
import re
+import shutil
import subprocess
import sys
import tempfile
@@ -198,7 +199,18 @@
if not line.startswith('?'):
continue
filename = line[1:].strip()
- os.remove(os.path.join(svn_repo, filename))
+ filepath = os.path.abspath(os.path.join(svn_repo, filename))
+ abs_svn_repo = os.path.abspath(svn_repo)
+ # Safety check that the directory we are about to delete is
+ # actually within our svn staging dir.
+ if not filepath.startswith(abs_svn_repo):
+ die("Path to clean (%s) is not in svn staging dir (%s)"
+ % (filepath, abs_svn_repo))
+
+ if os.path.isdir(filepath):
+ shutil.rmtree(filepath)
+ else:
+ os.remove(filepath)
def svn_init(svn_root):
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59236.190212.patch
Type: text/x-patch
Size: 1010 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190312/39dec6d2/attachment.bin>
More information about the llvm-commits
mailing list