Skip to content

Conversation

thonkle
Copy link

@thonkle thonkle commented Feb 14, 2022

Specifying ports outside of the bounds of 1 - 65535 give unexpected behaviors:

  • 0 assigns a random port
  • less than 0 underflows
  • greater than 65535 overflows and then assigns a random port

This patch alerts the user that port numbers in these ranges are invalid.

@thonkle
Copy link
Author

thonkle commented Feb 14, 2022

Since this patch touches the init pathway, it does not appear to be a good candidate for unit testing. And a functional test case for this behavior did not appear to belong in any existing functional test (a new test seems too heavy handed).

Please advise.

@ghost
Copy link

ghost commented Feb 14, 2022

Isn't this already being addressed in #22087 ?

@thonkle
Copy link
Author

thonkle commented Feb 15, 2022

Isn't this already being addressed in #22087 ?

Looks like it. I will comment there since the bounds checking is not sufficient.

@DrahtBot
Copy link
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #16545 (refactor: Implement missing error checking for ArgsManager flags by ryanofsky)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@fanquake
Copy link
Member

fanquake commented Oct 2, 2022

Closing as a duplicate of #22087. The comments were left and addressed in that PR.

@fanquake fanquake closed this Oct 2, 2022
fanquake added a commit to bitcoin-core/gui that referenced this pull request Oct 12, 2022
0452678 Validate `port` options (amadeuszpawlik)
f8387c4 Validate 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 bitcoin/bitcoin#24116 and bitcoin/bitcoin#24344, port "0" is considered invalid too.
  Proposed in bitcoin/bitcoin#21893 (comment)

  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:
    utACK 0452678
  ryanofsky:
    Code review ACK 0452678. Just suggested changes since last review: reverting some SplitHostPort changes, adding release notes, avoiding 'GetArgs[0]` problem.

Tree-SHA512: f1ac80bf98520b287a6413ceadb41bc3a93c491955de9b9319ee1298ac0ab982751905762a287e748997ead6198a8bb7a3bc8817ac9e3d2468e11ab4a0f8496d
@bitcoin bitcoin locked and limited conversation to collaborators Oct 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants