From 89576ccc572fcaf9fb7117ad6124482cc95fbd9f Mon Sep 17 00:00:00 2001 From: stickies-v Date: Wed, 31 Aug 2022 14:34:53 +0100 Subject: [PATCH] refactor: add LIFETIMEBOUND to blockfilter where needed Ensure that the return values do not have a lifetime that exceeds the lifetime of what it is bound to. See https://github.com/bitcoin/bitcoin/blob/master/doc/developer-notes.md#lifetimebound --- src/blockfilter.h | 11 ++++++----- src/index/blockfilterindex.h | 5 +++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/blockfilter.h b/src/blockfilter.h index d6a51e95c24..0cb627d9df2 100644 --- a/src/blockfilter.h +++ b/src/blockfilter.h @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -65,8 +66,8 @@ public: GCSFilter(const Params& params, const ElementSet& elements); uint32_t GetN() const { return m_N; } - const Params& GetParams() const { return m_params; } - const std::vector& GetEncoded() const { return m_encoded; } + const Params& GetParams() const LIFETIMEBOUND { return m_params; } + const std::vector& GetEncoded() const LIFETIMEBOUND { return m_encoded; } /** * Checks if the element may be in the set. False positives are possible @@ -128,10 +129,10 @@ public: BlockFilter(BlockFilterType filter_type, const CBlock& block, const CBlockUndo& block_undo); BlockFilterType GetFilterType() const { return m_filter_type; } - const uint256& GetBlockHash() const { return m_block_hash; } - const GCSFilter& GetFilter() const { return m_filter; } + const uint256& GetBlockHash() const LIFETIMEBOUND { return m_block_hash; } + const GCSFilter& GetFilter() const LIFETIMEBOUND { return m_filter; } - const std::vector& GetEncodedFilter() const + const std::vector& GetEncodedFilter() const LIFETIMEBOUND { return m_filter.GetEncoded(); } diff --git a/src/index/blockfilterindex.h b/src/index/blockfilterindex.h index 968eccb6b36..a31f7e460ec 100644 --- a/src/index/blockfilterindex.h +++ b/src/index/blockfilterindex.h @@ -5,6 +5,7 @@ #ifndef BITCOIN_INDEX_BLOCKFILTERINDEX_H #define BITCOIN_INDEX_BLOCKFILTERINDEX_H +#include #include #include #include @@ -49,9 +50,9 @@ protected: bool CustomRewind(const interfaces::BlockKey& current_tip, const interfaces::BlockKey& new_tip) override; - BaseIndex::DB& GetDB() const override { return *m_db; } + BaseIndex::DB& GetDB() const LIFETIMEBOUND override { return *m_db; } - const char* GetName() const override { return m_name.c_str(); } + const char* GetName() const LIFETIMEBOUND override { return m_name.c_str(); } public: /** Constructs the index, which becomes available to be queried. */