diff options
author | Jürg Billeter <j@bitron.ch> | 2020-04-21 13:59:48 +0200 |
---|---|---|
committer | bst-marge-bot <marge-bot@buildstream.build> | 2020-04-27 08:32:32 +0000 |
commit | a1c85b03824bf5b01868ad08c866c79501db5356 (patch) | |
tree | 4db47a3891027b89ba26b3a5e0398c27cfef5314 /src/buildstream | |
parent | f1b44c1087ca665b46c4a22d48e566e5938cfd67 (diff) | |
download | buildstream-a1c85b03824bf5b01868ad08c866c79501db5356.tar.gz |
_casbaseddirectory.py: Validate path components
This catches incorrect use of the `Directory` API.
Diffstat (limited to 'src/buildstream')
-rw-r--r-- | src/buildstream/storage/_casbaseddirectory.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/buildstream/storage/_casbaseddirectory.py b/src/buildstream/storage/_casbaseddirectory.py index 0a5a557b4..484dc0789 100644 --- a/src/buildstream/storage/_casbaseddirectory.py +++ b/src/buildstream/storage/_casbaseddirectory.py @@ -329,6 +329,8 @@ class CasBasedDirectory(Directory): if not path: continue + self.__validate_path_component(path) + entry = current_dir.index.get(path) if entry: @@ -726,6 +728,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: @@ -825,6 +828,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: @@ -864,3 +868,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)) |