Skip to content

Commit

Permalink
Merge dashpay#6544: fix: port 0 is not a bad one
Browse files Browse the repository at this point in the history
8c30f73 test: check port 0 in netbase_tests.cpp (UdjinM6)
c5eb184 fix: port 0 is not a bad one (UdjinM6)

Pull request description:

  ## Issue being fixed or feature implemented

  ```
  An ephemeral port is allocated to a socket in the following circumstances:

            *  the port number in a socket address is specified as 0 when
               calling bind(2);
  ```
  [source](https://man7.org/linux/man-pages/man7/ip.7.html#:~:text=An%20ephemeral%20port%20is%20allocated%20to%20a%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20socket%20in%20the%20following%20circumstances%3A%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%E2%80%A2%20%20the%20port%20number%20in%20a%20socket%20address%20is%20specified%20as%200%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20when%20calling%20bind(2)%3B)

  dashpay#6535 follow-up

  ## What was done?

  ## How Has This Been Tested?

  ## Breaking Changes

  ## Checklist:
  - [ ] I have performed a self-review of my own code
  - [ ] I have commented my code, particularly in hard-to-understand areas
  - [ ] I have added or updated relevant unit/integration/functional/e2e tests
  - [ ] I have made corresponding changes to the documentation
  - [ ] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_

ACKs for top commit:
  kwvg:
    utACK 8c30f73
  PastaPastaPasta:
    utACK 8c30f73; nit, could've been one commit

Tree-SHA512: f9a2767c1d9534e592e26a5332deab0d5c764a56ae783aece2f3b5bf0f2c3a258eac4fc2c16bf37fd5c1aae639bda14e43558849ad8229521b0830b9ec042aef
  • Loading branch information
PastaPastaPasta committed Jan 30, 2025
2 parents 9e39a84 + 8c30f73 commit 2f15c2b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/netbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ bool IsBadPort(uint16_t port)
{
/* Don't forget to update doc/p2p-bad-ports.md if you change this list. */

if (port <= PRIVILEGED_PORTS_THRESHOLD) return true;
if (port > 0 && port <= PRIVILEGED_PORTS_THRESHOLD) return true;
switch (port) {
case 1719: // h323gatestat
case 1720: // h323hostcall
Expand Down
1 change: 1 addition & 0 deletions src/test/netbase_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ BOOST_AUTO_TEST_CASE(isbadport)
BOOST_CHECK(IsBadPort(18332));
BOOST_CHECK(IsBadPort(18333));

BOOST_CHECK(!IsBadPort(0));
BOOST_CHECK(!IsBadPort(9998));
BOOST_CHECK(!IsBadPort(9999));
BOOST_CHECK(!IsBadPort(26656));
Expand Down

0 comments on commit 2f15c2b

Please sign in to comment.