mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 10:43:19 -03:00
Merge bitcoin/bitcoin#26213: rpc: Strict type checking for RPC boolean parameters
fa0153e609
refactor: Replace isTrue with get_bool (MarcoFalke)fa2cc5d1d6
bugfix: Strict type checking for RPC boolean parameters (MarcoFalke) Pull request description: ACKs for top commit: ryanofsky: Code review ACKfa0153e609
furszy: Code ACKfa0153e6
Tree-SHA512: b221f823c69d90c94447fd491071ff3659cfd512872b495ebc3e711f50633351974102c9ef7e50fa4a393c4131d349adea8fd41cc9d66f1f31e1f5e7a5f78757
This commit is contained in:
commit
3b5fb6e77a
5 changed files with 16 additions and 10 deletions
8
doc/release-notes-26213.md
Normal file
8
doc/release-notes-26213.md
Normal file
|
@ -0,0 +1,8 @@
|
|||
Low-level changes
|
||||
=================
|
||||
|
||||
- Previously `setban`, `addpeeraddress`, `walletcreatefundedpsbt`, methods
|
||||
allowed non-boolean and non-null values to be passed as boolean parameters.
|
||||
Any string, number, array, or object value that was passed would be treated
|
||||
as false. After this change, passing any value except `true`, `false`, or
|
||||
`null` now triggers a JSON value is not of expected type error. (#26213)
|
|
@ -731,9 +731,7 @@ static RPCHelpMan setban()
|
|||
if (!request.params[2].isNull())
|
||||
banTime = request.params[2].getInt<int64_t>();
|
||||
|
||||
bool absolute = false;
|
||||
if (request.params[3].isTrue())
|
||||
absolute = true;
|
||||
const bool absolute{request.params[3].isNull() ? false : request.params[3].get_bool()};
|
||||
|
||||
if (isSubnet) {
|
||||
node.banman->Ban(subNet, banTime, absolute);
|
||||
|
@ -942,7 +940,7 @@ static RPCHelpMan addpeeraddress()
|
|||
|
||||
const std::string& addr_string{request.params[0].get_str()};
|
||||
const auto port{request.params[1].getInt<uint16_t>()};
|
||||
const bool tried{request.params[2].isTrue()};
|
||||
const bool tried{request.params[2].isNull() ? false : request.params[2].get_bool()};
|
||||
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
CNetAddr net_addr;
|
||||
|
|
|
@ -304,7 +304,7 @@ static RPCHelpMan createrawtransaction()
|
|||
|
||||
std::optional<bool> rbf;
|
||||
if (!request.params[3].isNull()) {
|
||||
rbf = request.params[3].isTrue();
|
||||
rbf = request.params[3].get_bool();
|
||||
}
|
||||
CMutableTransaction rawTx = ConstructTransaction(request.params[0], request.params[1], request.params[2], rbf);
|
||||
|
||||
|
@ -1449,7 +1449,7 @@ static RPCHelpMan createpsbt()
|
|||
|
||||
std::optional<bool> rbf;
|
||||
if (!request.params[3].isNull()) {
|
||||
rbf = request.params[3].isTrue();
|
||||
rbf = request.params[3].get_bool();
|
||||
}
|
||||
CMutableTransaction rawTx = ConstructTransaction(request.params[0], request.params[1], request.params[2], rbf);
|
||||
|
||||
|
|
|
@ -1651,11 +1651,8 @@ RPCHelpMan walletcreatefundedpsbt()
|
|||
|
||||
CAmount fee;
|
||||
int change_position;
|
||||
bool rbf{wallet.m_signal_rbf};
|
||||
const UniValue &replaceable_arg = options["replaceable"];
|
||||
if (!replaceable_arg.isNull()) {
|
||||
rbf = replaceable_arg.isTrue();
|
||||
}
|
||||
const bool rbf{replaceable_arg.isNull() ? wallet.m_signal_rbf : replaceable_arg.get_bool()};
|
||||
CMutableTransaction rawTx = ConstructTransaction(request.params[0], request.params[1], request.params[2], rbf);
|
||||
CCoinControl coin_control;
|
||||
// Automatically select coins, unless at least one is manually selected. Can
|
||||
|
|
|
@ -307,6 +307,9 @@ class NetTest(BitcoinTestFramework):
|
|||
assert_equal(node.addpeeraddress(address="", port=8333), {"success": False})
|
||||
assert_equal(node.getnodeaddresses(count=0), [])
|
||||
|
||||
self.log.debug("Test that non-bool tried fails")
|
||||
assert_raises_rpc_error(-3, "JSON value of type string is not of expected type bool", self.nodes[0].addpeeraddress, address="1.2.3.4", tried="True", port=1234)
|
||||
|
||||
self.log.debug("Test that adding an address with invalid port fails")
|
||||
assert_raises_rpc_error(-1, "JSON integer out of range", self.nodes[0].addpeeraddress, address="1.2.3.4", port=-1)
|
||||
assert_raises_rpc_error(-1, "JSON integer out of range", self.nodes[0].addpeeraddress,address="1.2.3.4", port=65536)
|
||||
|
|
Loading…
Add table
Reference in a new issue