mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-08 19:53:27 +01:00
Merge bitcoin/bitcoin#30679: fix: handle invalid -rpcbind port earlier
e6994efe08fix: increase rpcbind check robustness (tdb3)d38e3aed89fix: handle invalid rpcbind port earlier (tdb3)83b67f2e6drefactor: move host/port checking (tdb3)73c243965atest: add tests for invalid rpcbind ports (tdb3) Pull request description: Previously, when an invalid port was specified in `-rpcbind`, the `SplitHostPort()` return value in `HTTPBindAddresses()` was ignored and attempt would be made to bind to the default rpcbind port (with the host/port treated as a host). This rearranges port checking code in `AppInitMain()` to handle the invalid port before reaching `HTTPBindAddresses()`. Also adds a check in `HTTPBindAddresses()` as a defensive measure for future changes. Adds then updates associated functional tests as well. ACKs for top commit: achow101: ACKe6994efe08ryanofsky: Code review ACKe6994efe08zaidmstrr: Code review ACK [e6994ef](e6994efe08) Tree-SHA512: bcc3e5ceef21963821cd16ce6ecb83d5c5657755882c05872a7cfe661a1492b1d631f54de22f41fdd173512d62dd15dc37e394fe1a7abe4de484b82cd2438b92
This commit is contained in:
@@ -45,6 +45,19 @@ class RPCBindTest(BitcoinTestFramework):
|
||||
assert_equal(set(get_bind_addrs(pid)), set(expected))
|
||||
self.stop_nodes()
|
||||
|
||||
def run_invalid_bind_test(self, allow_ips, addresses):
|
||||
'''
|
||||
Attempt to start a node with requested rpcallowip and rpcbind
|
||||
parameters, expecting that the node will fail.
|
||||
'''
|
||||
self.log.info(f'Invalid bind test for {addresses}')
|
||||
base_args = ['-disablewallet', '-nolisten']
|
||||
if allow_ips:
|
||||
base_args += ['-rpcallowip=' + x for x in allow_ips]
|
||||
init_error = 'Error: Invalid port specified in -rpcbind: '
|
||||
for addr in addresses:
|
||||
self.nodes[0].assert_start_raises_init_error(base_args + [f'-rpcbind={addr}'], init_error + f"'{addr}'")
|
||||
|
||||
def run_allowip_test(self, allow_ips, rpchost, rpcport):
|
||||
'''
|
||||
Start a node with rpcallow IP, and request getnetworkinfo
|
||||
@@ -84,6 +97,10 @@ class RPCBindTest(BitcoinTestFramework):
|
||||
|
||||
if not self.options.run_nonloopback:
|
||||
self._run_loopback_tests()
|
||||
if self.options.run_ipv4:
|
||||
self.run_invalid_bind_test(['127.0.0.1'], ['127.0.0.1:notaport', '127.0.0.1:-18443', '127.0.0.1:0', '127.0.0.1:65536'])
|
||||
if self.options.run_ipv6:
|
||||
self.run_invalid_bind_test(['[::1]'], ['[::1]:notaport', '[::1]:-18443', '[::1]:0', '[::1]:65536'])
|
||||
if not self.options.run_ipv4 and not self.options.run_ipv6:
|
||||
self._run_nonloopback_tests()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user