[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:40:26 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL355896: Fix git-llvm crashing when trying to remove directory while cleaning (authored by teemperor, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D59236?vs=190212&id=190214#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59236/new/

https://reviews.llvm.org/D59236

Files:
  llvm/trunk/utils/git-svn/git-llvm


Index: llvm/trunk/utils/git-svn/git-llvm
===================================================================
--- llvm/trunk/utils/git-svn/git-llvm
+++ llvm/trunk/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.190214.patch
Type: text/x-patch
Size: 1028 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190312/414fb6dc/attachment.bin>


More information about the llvm-commits mailing list