-
Notifications
You must be signed in to change notification settings - Fork 38.6k
net processing: clamp PeerManager::Options user input #28149
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
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. |
glozow
left a comment
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 128ad03792cd4aeeaf32807d07f01e3f85adaf28
Thanks for the followup
dergoegge
left a comment
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
dergoegge
left a comment
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
|
|
||
| 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.
|
|
||
| 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?
glozow
left a comment
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
Summary: Document PeerManager::Options members. Clamp -maxorphantx to uint32_t bounds. Clamp -blockreconstructionextratxn to uint32_t bounds. Also changes max_extra_txs into a uint32_t to avoid platform-specific behaviour. -maxaddrtosend is hidden option used only for tests, so we only do minimal boundary checks. This is a backport of [[ bitcoin/bitcoin#28149 | core#28149 ]] Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D16456
Summary: Document PeerManager::Options members. Clamp -maxorphantx to uint32_t bounds. Clamp -blockreconstructionextratxn to uint32_t bounds. Also changes max_extra_txs into a uint32_t to avoid platform-specific behaviour. -maxaddrtosend is hidden option used only for tests, so we only do minimal boundary checks. This is a backport of [[ bitcoin/bitcoin#28149 | core#28149 ]] Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D16456
Avoid out-of-bounds user input for
PeerManager::Optionsby safely clamping-maxorphantxand-blockreconstructionextratxn, and avoid platform-specific behaviour by changingPeerManager::Options::max_extra_txsfromsize_tto auint32_t. Addresses #27499 (review).Also documents all
PeerManager::Optionsmembers, addressing #27499 (comment).