aboutsummaryrefslogtreecommitdiff
path: root/src/netbase.cpp
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2015-05-26 08:59:20 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2015-05-26 08:59:59 +0200
commitb45c50ce511dbf541ea086ae40a3ad16ff06de0c (patch)
tree8164631756d441bb812db9ff0f84022c197f4fa4 /src/netbase.cpp
parent19e8d7be42039724b4893515ec6457d0187024a9 (diff)
downloadbitcoin-b45c50ce511dbf541ea086ae40a3ad16ff06de0c.tar.xz
Fix two problems in CSubNet parsing
Fix two CSubNet constructor problems: - The use of `/x` where 8 does not divide x was broken, due to a bit-order issue - The use of e.g. `1.2.3.4/24` where the netmasked bits in the network are not 0 was broken. Fix this by explicitly normalizing the netwok according to the bitmask. Also add tests for these cases. Fixes #6179. Thanks to @jonasschnelli for reporting and initial fix.
Diffstat (limited to 'src/netbase.cpp')
-rw-r--r--src/netbase.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/netbase.cpp b/src/netbase.cpp
index b765b35eec..41cc18d3cd 100644
--- a/src/netbase.cpp
+++ b/src/netbase.cpp
@@ -1260,7 +1260,7 @@ CSubNet::CSubNet(const std::string &strSubnet, bool fAllowLookup)
n += astartofs*8;
// Clear bits [n..127]
for (; n < 128; ++n)
- netmask[n>>3] &= ~(1<<(n&7));
+ netmask[n>>3] &= ~(1<<(7-(n&7)));
}
else
{
@@ -1287,6 +1287,10 @@ CSubNet::CSubNet(const std::string &strSubnet, bool fAllowLookup)
{
valid = false;
}
+
+ // Normalize network according to netmask
+ for(int x=0; x<16; ++x)
+ network.ip[x] &= netmask[x];
}
bool CSubNet::Match(const CNetAddr &addr) const