mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-22 23:07:59 +01:00
refactor: Use EnsureAnyNodeContext
node_context is never null, but if it was, it would lead to a nullptr dereference in node_context->scheduler. Just use EnsureAnyNodeContext everywhere for more robust, consistent, and correct code.
This commit is contained in:
parent
fa1640617e
commit
fabef121b0
1 changed files with 5 additions and 9 deletions
|
@ -57,11 +57,9 @@ static RPCHelpMan setmocktime()
|
||||||
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Mocktime cannot be negative: %s.", time));
|
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Mocktime cannot be negative: %s.", time));
|
||||||
}
|
}
|
||||||
SetMockTime(time);
|
SetMockTime(time);
|
||||||
auto node_context = util::AnyPtr<NodeContext>(request.context);
|
const NodeContext& node_context{EnsureAnyNodeContext(request.context)};
|
||||||
if (node_context) {
|
for (const auto& chain_client : node_context.chain_clients) {
|
||||||
for (const auto& chain_client : node_context->chain_clients) {
|
chain_client->setMockTime(time);
|
||||||
chain_client->setMockTime(time);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return UniValue::VNULL;
|
return UniValue::VNULL;
|
||||||
|
@ -89,10 +87,8 @@ static RPCHelpMan mockscheduler()
|
||||||
throw std::runtime_error("delta_time must be between 1 and 3600 seconds (1 hr)");
|
throw std::runtime_error("delta_time must be between 1 and 3600 seconds (1 hr)");
|
||||||
}
|
}
|
||||||
|
|
||||||
auto node_context = CHECK_NONFATAL(util::AnyPtr<NodeContext>(request.context));
|
const NodeContext& node_context{EnsureAnyNodeContext(request.context)};
|
||||||
// protect against null pointer dereference
|
CHECK_NONFATAL(node_context.scheduler)->MockForward(std::chrono::seconds{delta_seconds});
|
||||||
CHECK_NONFATAL(node_context->scheduler);
|
|
||||||
node_context->scheduler->MockForward(std::chrono::seconds(delta_seconds));
|
|
||||||
SyncWithValidationInterfaceQueue();
|
SyncWithValidationInterfaceQueue();
|
||||||
|
|
||||||
return UniValue::VNULL;
|
return UniValue::VNULL;
|
||||||
|
|
Loading…
Add table
Reference in a new issue