New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
net processing: clamp PeerManager::Options user input #28149
net processing: clamp PeerManager::Options user input #28149
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK 128ad03
Thanks for the followup
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK
Also changes max_extra_txs into a uint32_t to avoid platform-specific behaviour
128ad03
to
547fa52
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review ACK 547fa52
namespace node { | ||
|
||
void ApplyArgsManOptions(const ArgsManager& argsman, PeerManager::Options& options) | ||
{ | ||
if (auto value{argsman.GetBoolArg("-txreconciliation")}) options.reconcile_txs = *value; | ||
|
||
if (auto value{argsman.GetIntArg("-maxorphantx")}) { | ||
options.max_orphan_txs = uint32_t(std::max(int64_t{0}, *value)); | ||
options.max_orphan_txs = uint32_t((std::clamp<int64_t>(*value, 0, std::numeric_limits<uint32_t>::max()))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated: May be good to write a clang-tidy plugin to enforce the limits are compile-time constants and in range to avoid silent UB at runtime?
The in-range one can be submitted to upstream and the other check can be done in this repo.
namespace node { | ||
|
||
void ApplyArgsManOptions(const ArgsManager& argsman, PeerManager::Options& options) | ||
{ | ||
if (auto value{argsman.GetBoolArg("-txreconciliation")}) options.reconcile_txs = *value; | ||
|
||
if (auto value{argsman.GetIntArg("-maxorphantx")}) { | ||
options.max_orphan_txs = uint32_t(std::max(int64_t{0}, *value)); | ||
options.max_orphan_txs = uint32_t((std::clamp<int64_t>(*value, 0, std::numeric_limits<uint32_t>::max()))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
options.max_orphan_txs = uint32_t((std::clamp<int64_t>(*value, 0, std::numeric_limits<uint32_t>::max()))); | |
options.max_orphan_txs = uint32_t(std::clamp<int64_t>(*value, 0, std::numeric_limits<uint32_t>::max())); |
nit, if you re-touch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reACK 547fa52
Avoid out-of-bounds user input for
PeerManager::Options
by safely clamping-maxorphantx
and-blockreconstructionextratxn
, and avoid platform-specific behaviour by changingPeerManager::Options::max_extra_txs
fromsize_t
to auint32_t
. Addresses #27499 (review).Also documents all
PeerManager::Options
members, addressing #27499 (comment).