Skip to content

Commit

Permalink
rpcdaemon: fix use-after-free in erigon_getLatestLogs (#2617)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sixtysixter authored Dec 23, 2024
1 parent 2d84274 commit 62b69b0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
4 changes: 3 additions & 1 deletion silkworm/rpc/commands/erigon_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,9 @@ Task<void> ErigonRpcApi::handle_erigon_get_latest_logs(const nlohmann::json& req
auto tx = co_await database_->begin();

try {
LogsWalker logs_walker(*block_cache_, *tx, *backend_, workers_);
auto storage = tx->create_storage();
LogsWalker logs_walker(*block_cache_, *tx, *storage, *backend_, workers_);

const auto [start, end] = co_await logs_walker.get_block_nums(filter);
if (start == end && start == std::numeric_limits<std::uint64_t>::max()) {
auto error_msg = "invalid eth_getLogs filter block_hash: " + filter.block_hash.value();
Expand Down
15 changes: 11 additions & 4 deletions silkworm/rpc/commands/eth_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1516,7 +1516,8 @@ Task<void> EthereumRpcApi::handle_eth_new_filter(const nlohmann::json& request,
auto tx = co_await database_->begin();

try {
LogsWalker logs_walker{*block_cache_, *tx, *backend_, workers_};
auto storage = tx->create_storage();
LogsWalker logs_walker(*block_cache_, *tx, *storage, *backend_, workers_);

const auto [start, end] = co_await logs_walker.get_block_nums(filter);
filter.start = start;
Expand Down Expand Up @@ -1600,7 +1601,9 @@ Task<void> EthereumRpcApi::handle_eth_get_filter_logs(const nlohmann::json& requ
auto tx = co_await database_->begin();

try {
LogsWalker logs_walker{*block_cache_, *tx, *backend_, workers_};
auto storage = tx->create_storage();
LogsWalker logs_walker(*block_cache_, *tx, *storage, *backend_, workers_);

const auto [start, end] = co_await logs_walker.get_block_nums(filter);

if (filter.start != start && filter.end != end) {
Expand Down Expand Up @@ -1649,7 +1652,9 @@ Task<void> EthereumRpcApi::handle_eth_get_filter_changes(const nlohmann::json& r
auto tx = co_await database_->begin();

try {
LogsWalker logs_walker{*block_cache_, *tx, *backend_, workers_};
auto storage = tx->create_storage();
LogsWalker logs_walker(*block_cache_, *tx, *storage, *backend_, workers_);

const auto [start, end] = co_await logs_walker.get_block_nums(filter);

std::vector<Log> logs;
Expand Down Expand Up @@ -1717,7 +1722,9 @@ Task<void> EthereumRpcApi::handle_eth_get_logs(const nlohmann::json& request, st
auto tx = co_await database_->begin();

try {
LogsWalker logs_walker{*block_cache_, *tx, *backend_, workers_};
auto storage = tx->create_storage();
LogsWalker logs_walker(*block_cache_, *tx, *storage, *backend_, workers_);

const auto [start, end] = co_await logs_walker.get_block_nums(filter);
if (start == end && start == std::numeric_limits<std::uint64_t>::max()) {
auto error_msg = "invalid eth_getLogs filter block_hash: " + filter.block_hash.value();
Expand Down
4 changes: 2 additions & 2 deletions silkworm/rpc/core/logs_walker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ using boost::asio::awaitable;

class LogsWalker {
public:
explicit LogsWalker(BlockCache& block_cache, db::kv::api::Transaction& tx, ethbackend::BackEnd& backend, WorkerPool& workers)
: block_cache_(block_cache), tx_(tx), block_reader_(*tx.create_storage(), tx), backend_{backend}, workers_{workers} {}
explicit LogsWalker(BlockCache& block_cache, db::kv::api::Transaction& tx, const db::chain::ChainStorage& chain_storage, ethbackend::BackEnd& backend, WorkerPool& workers)
: block_cache_(block_cache), tx_(tx), block_reader_(chain_storage, tx), backend_{backend}, workers_{workers} {}

LogsWalker(const LogsWalker&) = delete;
LogsWalker& operator=(const LogsWalker&) = delete;
Expand Down

0 comments on commit 62b69b0

Please sign in to comment.