mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-26 06:48:53 +02:00
Merge bitcoin/bitcoin#22087: Validate port-options
04526787b5Validate `port` options (amadeuszpawlik)f8387c4234Validate port value in `SplitHostPort` (amadeuszpawlik) Pull request description: Validate `port`-options, so that invalid values are rejected early in the startup. Ports are `uint16_t`s, which effectively limits a port's value to <=65535. As discussed in https://github.com/bitcoin/bitcoin/pull/24116 and https://github.com/bitcoin/bitcoin/pull/24344, port "0" is considered invalid too. Proposed in https://github.com/bitcoin/bitcoin/issues/21893#issuecomment-835784223 The `SplitHostPort(std::string in, uint16_t& portOut, std::string& hostOut)` now returns a bool that indicates whether the port value was set and within the allowed range. This is an improvement that can be used not only for port validation of options at startup, but also in rpc calls, etc, ACKs for top commit: luke-jr: utACK04526787b5ryanofsky: Code review ACK04526787b5. Just suggested changes since last review: reverting some SplitHostPort changes, adding release notes, avoiding 'GetArgs[0]` problem. Tree-SHA512: f1ac80bf98520b287a6413ceadb41bc3a93c491955de9b9319ee1298ac0ab982751905762a287e748997ead6198a8bb7a3bc8817ac9e3d2468e11ab4a0f8496d
This commit is contained in:
@@ -317,19 +317,34 @@ class ProxyTest(BitcoinTestFramework):
|
||||
|
||||
self.stop_node(1)
|
||||
|
||||
self.log.info("Test passing invalid -proxy raises expected init error")
|
||||
self.nodes[1].extra_args = ["-proxy=abc:def"]
|
||||
msg = "Error: Invalid -proxy address or hostname: 'abc:def'"
|
||||
self.log.info("Test passing invalid -proxy hostname raises expected init error")
|
||||
self.nodes[1].extra_args = ["-proxy=abc..abc:23456"]
|
||||
msg = "Error: Invalid -proxy address or hostname: 'abc..abc:23456'"
|
||||
self.nodes[1].assert_start_raises_init_error(expected_msg=msg)
|
||||
|
||||
self.log.info("Test passing invalid -onion raises expected init error")
|
||||
self.nodes[1].extra_args = ["-onion=xyz:abc"]
|
||||
msg = "Error: Invalid -onion address or hostname: 'xyz:abc'"
|
||||
self.log.info("Test passing invalid -proxy port raises expected init error")
|
||||
self.nodes[1].extra_args = ["-proxy=192.0.0.1:def"]
|
||||
msg = "Error: Invalid port specified in -proxy: '192.0.0.1:def'"
|
||||
self.nodes[1].assert_start_raises_init_error(expected_msg=msg)
|
||||
|
||||
self.log.info("Test passing invalid -i2psam raises expected init error")
|
||||
self.nodes[1].extra_args = ["-i2psam=def:xyz"]
|
||||
msg = "Error: Invalid -i2psam address or hostname: 'def:xyz'"
|
||||
self.log.info("Test passing invalid -onion hostname raises expected init error")
|
||||
self.nodes[1].extra_args = ["-onion=xyz..xyz:23456"]
|
||||
msg = "Error: Invalid -onion address or hostname: 'xyz..xyz:23456'"
|
||||
self.nodes[1].assert_start_raises_init_error(expected_msg=msg)
|
||||
|
||||
self.log.info("Test passing invalid -onion port raises expected init error")
|
||||
self.nodes[1].extra_args = ["-onion=192.0.0.1:def"]
|
||||
msg = "Error: Invalid port specified in -onion: '192.0.0.1:def'"
|
||||
self.nodes[1].assert_start_raises_init_error(expected_msg=msg)
|
||||
|
||||
self.log.info("Test passing invalid -i2psam hostname raises expected init error")
|
||||
self.nodes[1].extra_args = ["-i2psam=def..def:23456"]
|
||||
msg = "Error: Invalid -i2psam address or hostname: 'def..def:23456'"
|
||||
self.nodes[1].assert_start_raises_init_error(expected_msg=msg)
|
||||
|
||||
self.log.info("Test passing invalid -i2psam port raises expected init error")
|
||||
self.nodes[1].extra_args = ["-i2psam=192.0.0.1:def"]
|
||||
msg = "Error: Invalid port specified in -i2psam: '192.0.0.1:def'"
|
||||
self.nodes[1].assert_start_raises_init_error(expected_msg=msg)
|
||||
|
||||
self.log.info("Test passing invalid -onlynet=i2p without -i2psam raises expected init error")
|
||||
|
||||
Reference in New Issue
Block a user