Skip to content

Conversation

@vasild
Copy link
Contributor

@vasild vasild commented Apr 13, 2021

PF_DOWNLOAD is 0b1000000 and
PF_NOBAN    is 0b1010000.

This makes a check like flags & PF_NOBAN return true even if flags
is equal to PF_DOWNLOAD.

If -whitebind=download@1.1.1.1:8765 is specified, then 1.1.1.1:8765
should be added to the list of local addresses. We only want to avoid
adding to local addresses (that are advertised) a whitebind that has
noban@ flag.

As a result of a mis-check in CConnman::Bind() we would not have added
1.1.1.1:8765 to the local addresses in the example above.

`PF_DOWNLOAD` is `0b1000000` and
`PF_NOBAN`    is `0b1010000`.

This makes a check like `flags & PF_NOBAN` return `true` even if `flags`
is equal to `PF_DOWNLOAD`.

If `-whitebind=download@1.1.1.1:8765` is specified, then `1.1.1.1:8765`
should be added to the list of local addresses. We only want to avoid
adding to local addresses (that are advertised) a whitebind that has
`noban@` flag.

As a result of a mis-check in `CConnman::Bind()` we would not have added
`1.1.1.1:8765` to the local addresses in the example above.
@vasild
Copy link
Contributor Author

vasild commented Apr 13, 2021

Similar issue spotted in #20196 (comment) by @jonatack. I checked that what's fixed in this PR is the only other case.

cc @hebasto, @NicolasDorier

@jonatack
Copy link
Member

Proposed in #21644.

@jonatack
Copy link
Member

jonatack commented Apr 13, 2021

(#21506 would eliminate this class of NetPermissionFlags bug as well, as only defined operations would compile.)

@DrahtBot DrahtBot added the P2P label Apr 13, 2021
@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:

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.

@vasild
Copy link
Contributor Author

vasild commented Apr 14, 2021

Closing in favor of #21644.

@vasild vasild closed this Apr 14, 2021
@vasild vasild deleted the fix_pf_noban_usage branch April 14, 2021 07:41
}

if (addr.IsRoutable() && fDiscover && !(flags & BF_DONT_ADVERTISE) && !(permissions & PF_NOBAN)) {
const bool noban{NetPermissions::HasFlag(static_cast<NetPermissionFlags>(flags), PF_NOBAN)};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I stared at this for a minute to figure out why the cast added. Then I realized it's because this line uses flags instead of permissions. The names are certainly similar enough to be confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, it is using the wrong variable 🤦

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice if there was a test that failed with this diff

@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants