From c11e9142d2a1b04004dcbed282dc1e04d116e03f Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Tue, 13 Jun 2023 17:35:05 +0200 Subject: ReadTree: Add check for non-upwards symlinks... ...as early as possible. This ensures that callers always receive only the tree entries for the supported object types. For the symlinks non-upwardness check we pass a lambda capturing the real backend of the tree entries, such that the symlinks can be read. Updates git_tree tests accordingly. --- src/buildtool/file_system/git_repo.hpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src/buildtool/file_system/git_repo.hpp') diff --git a/src/buildtool/file_system/git_repo.hpp b/src/buildtool/file_system/git_repo.hpp index 43c5fa22..e96f401b 100644 --- a/src/buildtool/file_system/git_repo.hpp +++ b/src/buildtool/file_system/git_repo.hpp @@ -17,6 +17,7 @@ #include +#include "src/buildtool/common/bazel_types.hpp" #include "src/buildtool/file_system/git_cas.hpp" extern "C" { @@ -48,6 +49,11 @@ class GitRepo { using tree_entries_t = std::unordered_map>; + // Checks whether a list of symlinks given by their hashes are non-upwards, + // based on content read from an actual backend. + using SymlinksCheckFunc = + std::function const&)>; + GitRepo() = delete; // no default ctor ~GitRepo() noexcept = default; @@ -80,9 +86,11 @@ class GitRepo { /// Reading a tree must be backed by an object database. Therefore, a real /// repository is required. /// \param id The object id. + /// \param check_symlinks Function to check non-upwardness condition. /// \param is_hex_id Specify whether `id` is hex string or raw. /// \param ignore_special If set, treat symlinks as absent. [[nodiscard]] auto ReadTree(std::string const& id, + SymlinksCheckFunc const& check_symlinks, bool is_hex_id = false, bool ignore_special = false) const noexcept -> std::optional; @@ -100,12 +108,14 @@ class GitRepo { /// \brief Read entries from tree data (without object db). /// \param data The tree object as plain data. /// \param id The object id. + /// \param check_symlinks Function to check non-upwardness condition. /// \param is_hex_id Specify whether `id` is hex string or raw. /// \returns The tree entries. - [[nodiscard]] static auto ReadTreeData(std::string const& data, - std::string const& id, - bool is_hex_id = false) noexcept - -> std::optional; + [[nodiscard]] static auto ReadTreeData( + std::string const& data, + std::string const& id, + SymlinksCheckFunc const& check_symlinks, + bool is_hex_id = false) noexcept -> std::optional; /// \brief Create a flat shallow (without objects in db) tree and return it. /// Creates a tree object from the entries without access to the actual -- cgit v1.2.3