Skip to content

Commit dde69f2

Browse files
jonatackvasild
andcommitted
p2p, bugfix: use NetPermissions::HasFlag() in CConnman::Bind()
PF_NOBAN is a multi-flag that includes PF_DOWNLOAD, so the conditional in CConnman::Bind() using a bitwise AND will return the same result for both the "noban" status and the "download" status. Example: `PF_DOWNLOAD` is `0b1000000` `PF_NOBAN` is `0b1010000` This makes a check like `flags & PF_NOBAN` return `true` even if `flags` is equal to `PF_DOWNLOAD`. If `[email protected]: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 a `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. Co-authored-by: Vasil Dimov <[email protected]>
1 parent f0fa324 commit dde69f2

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/net.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2408,8 +2408,9 @@ NodeId CConnman::GetNewNodeId()
24082408

24092409

24102410
bool CConnman::Bind(const CService &addr, unsigned int flags, NetPermissionFlags permissions) {
2411-
if (!(flags & BF_EXPLICIT) && !IsReachable(addr))
2411+
if (!(flags & BF_EXPLICIT) && !IsReachable(addr)) {
24122412
return false;
2413+
}
24132414
bilingual_str strError;
24142415
if (!BindListenPort(addr, strError, permissions)) {
24152416
if ((flags & BF_REPORT_ERROR) && clientInterface) {
@@ -2418,7 +2419,7 @@ bool CConnman::Bind(const CService &addr, unsigned int flags, NetPermissionFlags
24182419
return false;
24192420
}
24202421

2421-
if (addr.IsRoutable() && fDiscover && !(flags & BF_DONT_ADVERTISE) && !(permissions & PF_NOBAN)) {
2422+
if (addr.IsRoutable() && fDiscover && !(flags & BF_DONT_ADVERTISE) && !NetPermissions::HasFlag(permissions, NetPermissionFlags::PF_NOBAN)) {
24222423
AddLocal(addr, LOCAL_BIND);
24232424
}
24242425

0 commit comments

Comments
 (0)