summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2020-04-21 13:59:48 +0200
committerJürg Billeter <j@bitron.ch>2020-04-21 16:21:36 +0200
commitc418f94c424a1d169652c96e2c37a387442c6caa (patch)
tree4204de50e1358c6b1f723cbe24126377dab6ea9b
parent6c6d8f8c9c1dbe5a8990869daff469976bdbc0b2 (diff)
downloadbuildstream-juerg/validate-path.tar.gz
_casbaseddirectory.py: Validate path componentsjuerg/validate-path
-rw-r--r--src/buildstream/storage/_casbaseddirectory.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/buildstream/storage/_casbaseddirectory.py b/src/buildstream/storage/_casbaseddirectory.py
index e33bdc3d7..3dcf4fcb0 100644
--- a/src/buildstream/storage/_casbaseddirectory.py
+++ b/src/buildstream/storage/_casbaseddirectory.py
@@ -332,6 +332,8 @@ class CasBasedDirectory(Directory):
if not path:
continue
+ self.__validate_path_component(path)
+
entry = current_dir.index.get(path)
if entry:
@@ -729,6 +731,7 @@ class CasBasedDirectory(Directory):
@contextmanager
def open_file(self, *path: str, mode: str = "r"):
subdir = self.descend(*path[:-1])
+ self.__validate_path_component(path[-1])
entry = subdir.index.get(path[-1])
if entry and entry.type != _FileType.REGULAR_FILE:
@@ -828,6 +831,7 @@ class CasBasedDirectory(Directory):
def exists(self, *path, follow_symlinks=False):
try:
subdir = self.descend(*path[:-1], follow_symlinks=follow_symlinks)
+ self.__validate_path_component(path[-1])
target = subdir.index.get(path[-1])
if target is not None:
if follow_symlinks and target.type == _FileType.SYMLINK:
@@ -867,3 +871,7 @@ class CasBasedDirectory(Directory):
subdir.__add_files_to_result(path_prefix=relative_pathname, result=result)
else:
result.files_written.append(relative_pathname)
+
+ def __validate_path_component(self, path):
+ if "/" in path:
+ raise VirtualDirectoryError("Invalid path component: '{}'".format(path))