Skip to content

Commit 0d9a13d

Browse files
committed
Merge bitcoin/bitcoin#28149: net processing: clamp PeerManager::Options user input
547fa52 net processing: clamp -blockreconstructionextratxn to uint32_t bounds (stickies-v) e451d1e net processing: clamp -maxorphantx to uint32_t bounds (stickies-v) aa89e04 doc: document PeerManager::Options members (stickies-v) Pull request description: Avoid out-of-bounds user input for `PeerManager::Options` by safely clamping `-maxorphantx` and `-blockreconstructionextratxn`, and avoid platform-specific behaviour by changing `PeerManager::Options::max_extra_txs` from `size_t` to a `uint32_t`. Addresses bitcoin/bitcoin#27499 (review). Also documents all `PeerManager::Options` members, addressing bitcoin/bitcoin#27499 (comment). ACKs for top commit: dergoegge: Code review ACK 547fa52 glozow: reACK 547fa52 Tree-SHA512: 042d47b35bb8a7b29ef3dadd4c0c5d26f13a8f174f33687855d603c19f8de0fcbbda94418453331e149885412d4edd5f402d640d938f6d94b4dcf54e2fdbbcc9
2 parents 4922570 + 547fa52 commit 0d9a13d

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/net_processing.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ class ChainstateManager;
1717
/** Whether transaction reconciliation protocol should be enabled by default. */
1818
static constexpr bool DEFAULT_TXRECONCILIATION_ENABLE{false};
1919
/** Default for -maxorphantx, maximum number of orphan transactions kept in memory */
20-
static const unsigned int DEFAULT_MAX_ORPHAN_TRANSACTIONS = 100;
21-
/** Default number of orphan+recently-replaced txn to keep around for block reconstruction */
22-
static const unsigned int DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN = 100;
20+
static const uint32_t DEFAULT_MAX_ORPHAN_TRANSACTIONS{100};
21+
/** Default number of non-mempool transactions to keep around for block reconstruction. Includes
22+
orphan, replaced, and rejected transactions. */
23+
static const uint32_t DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN{100};
2324
static const bool DEFAULT_PEERBLOOMFILTERS = false;
2425
static const bool DEFAULT_PEERBLOCKFILTERS = false;
2526
/** Threshold for marking a node to be discouraged, e.g. disconnected and added to the discouragement filter. */
@@ -46,11 +47,16 @@ class PeerManager : public CValidationInterface, public NetEventsInterface
4647
{
4748
public:
4849
struct Options {
49-
/** Whether this node is running in -blocksonly mode */
50+
//! Whether this node is running in -blocksonly mode
5051
bool ignore_incoming_txs{DEFAULT_BLOCKSONLY};
52+
//! Whether transaction reconciliation protocol is enabled
5153
bool reconcile_txs{DEFAULT_TXRECONCILIATION_ENABLE};
54+
//! Maximum number of orphan transactions kept in memory
5255
uint32_t max_orphan_txs{DEFAULT_MAX_ORPHAN_TRANSACTIONS};
53-
size_t max_extra_txs{DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN};
56+
//! Number of non-mempool transactions to keep around for block reconstruction. Includes
57+
//! orphan, replaced, and rejected transactions.
58+
uint32_t max_extra_txs{DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN};
59+
//! Whether all P2P messages are captured to disk
5460
bool capture_messages{false};
5561
};
5662

src/node/peerman_args.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,21 @@
33
#include <common/args.h>
44
#include <net_processing.h>
55

6+
#include <algorithm>
7+
#include <limits>
8+
69
namespace node {
710

811
void ApplyArgsManOptions(const ArgsManager& argsman, PeerManager::Options& options)
912
{
1013
if (auto value{argsman.GetBoolArg("-txreconciliation")}) options.reconcile_txs = *value;
1114

1215
if (auto value{argsman.GetIntArg("-maxorphantx")}) {
13-
options.max_orphan_txs = uint32_t(std::max(int64_t{0}, *value));
16+
options.max_orphan_txs = uint32_t((std::clamp<int64_t>(*value, 0, std::numeric_limits<uint32_t>::max())));
1417
}
1518

1619
if (auto value{argsman.GetIntArg("-blockreconstructionextratxn")}) {
17-
options.max_extra_txs = size_t(std::max(int64_t{0}, *value));
20+
options.max_extra_txs = uint32_t((std::clamp<int64_t>(*value, 0, std::numeric_limits<uint32_t>::max())));
1821
}
1922

2023
if (auto value{argsman.GetBoolArg("-capturemessages")}) options.capture_messages = *value;

0 commit comments

Comments
 (0)