summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim MacArthur <jim.macarthur@codethink.co.uk>2018-10-25 16:48:07 +0100
committerJim MacArthur <jim.macarthur@codethink.co.uk>2018-10-29 11:09:54 +0000
commit5fc7d6b407edc3a4335144e4658f5e52a5ec13cd (patch)
tree6de3978a40fcbe9c3bc4024db068fc5f19bc1d81
parent14623feb9c455754853b39c218b19233a31dd57a (diff)
downloadbuildstream-5fc7d6b407edc3a4335144e4658f5e52a5ec13cd.tar.gz
Detect infinite symlink loops in resolve()
-rw-r--r--buildstream/storage/_casbaseddirectory.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/buildstream/storage/_casbaseddirectory.py b/buildstream/storage/_casbaseddirectory.py
index 3388cfca7..ce0ec2bd2 100644
--- a/buildstream/storage/_casbaseddirectory.py
+++ b/buildstream/storage/_casbaseddirectory.py
@@ -388,7 +388,7 @@ class CasBasedDirectory(Directory):
return directory
- def _resolve(self, name, absolute_symlinks_resolve=True, force_create=False):
+ def _resolve(self, name, absolute_symlinks_resolve=True, force_create=False, first_seen_object = None):
""" Resolves any name to an object. If the name points to a symlink in
this directory, it returns the thing it points to,
recursively. Returns a CasBasedDirectory, FileNode or
@@ -407,6 +407,14 @@ class CasBasedDirectory(Directory):
return index_entry.pb_object
assert isinstance(index_entry.pb_object, remote_execution_pb2.SymlinkNode)
+
+ if first_seen_object is None:
+ first_seen_object = index_entry.pb_object
+ else:
+ if index_entry.pb_object == first_seen_object:
+ ### Infinite symlink loop detected ###
+ return None
+
print("Resolving '{}': This is a symlink node in the current directory.".format(name))
symlink = index_entry.pb_object
components = symlink.target.split(CasBasedDirectory._pb2_path_sep)
@@ -440,7 +448,7 @@ class CasBasedDirectory(Directory):
directory = directory.parent
else:
if c in directory.index:
- f = directory._resolve(c, absolute_symlinks_resolve)
+ f = directory._resolve(c, absolute_symlinks_resolve, first_seen_object=first_seen_object)
# Ultimately f must now be a file or directory
if isinstance(f, CasBasedDirectory):
directory = f