mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-05-03 08:21:29 +02:00
Sanitize port in addpeeraddress()
- Ensures port sanitization in `addpeeraddress()` - Adds test to check for invalid port values
This commit is contained in:
parent
225e5b57b2
commit
ada8358ef5
@ -932,7 +932,7 @@ static RPCHelpMan addpeeraddress()
|
|||||||
}
|
}
|
||||||
|
|
||||||
const std::string& addr_string{request.params[0].get_str()};
|
const std::string& addr_string{request.params[0].get_str()};
|
||||||
const uint16_t port{static_cast<uint16_t>(request.params[1].get_int())};
|
const auto port{request.params[1].getInt<uint16_t>()};
|
||||||
const bool tried{request.params[2].isTrue()};
|
const bool tried{request.params[2].isTrue()};
|
||||||
|
|
||||||
UniValue obj(UniValue::VOBJ);
|
UniValue obj(UniValue::VOBJ);
|
||||||
|
@ -257,6 +257,10 @@ class NetTest(BitcoinTestFramework):
|
|||||||
assert_equal(node.addpeeraddress(address="", port=8333), {"success": False})
|
assert_equal(node.addpeeraddress(address="", port=8333), {"success": False})
|
||||||
assert_equal(node.getnodeaddresses(count=0), [])
|
assert_equal(node.getnodeaddresses(count=0), [])
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
self.log.debug("Test that adding a valid address to the tried table succeeds")
|
self.log.debug("Test that adding a valid address to the tried table succeeds")
|
||||||
assert_equal(node.addpeeraddress(address="1.2.3.4", tried=True, port=8333), {"success": True})
|
assert_equal(node.addpeeraddress(address="1.2.3.4", tried=True, port=8333), {"success": True})
|
||||||
with node.assert_debug_log(expected_msgs=["CheckAddrman: new 0, tried 1, total 1 started"]):
|
with node.assert_debug_log(expected_msgs=["CheckAddrman: new 0, tried 1, total 1 started"]):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user