While working on the RPC ban function, i have detected the the CSubNet CIDR netmask calculations as well as the CSubNet::Match() function are buggy.
Edit: fixes #6179
While working on the RPC ban function, i have detected the the CSubNet CIDR netmask calculations as well as the CSubNet::Match() function are buggy.
Edit: fixes #6179
1270 | + { 1271 | + netmask[15-i] = netmask[15-i] << shift; 1272 | + break; 1273 | + } 1274 | + shift-=8; 1275 | + }
This is not so one-linerish. My cleverness is limited. I hope someone finds the time to do this nicer.
Trying a different take on this
108 | @@ -109,6 +109,11 @@ BOOST_AUTO_TEST_CASE(subnet_test) 109 | BOOST_CHECK(CSubNet("1.2.3.0/24") != CSubNet("1.2.4.0/255.255.255.0")); 110 | BOOST_CHECK(CSubNet("1.2.3.0/24").Match(CNetAddr("1.2.3.4"))); 111 | BOOST_CHECK(!CSubNet("1.2.2.0/24").Match(CNetAddr("1.2.3.4"))); 112 | + 113 | + BOOST_CHECK(CSubNet("1.2.2.1/24").Match(CNetAddr("1.2.2.4")));
So to be clear: these tests fail without this change?
I doubt you need as many changes to fix this. Particularly the change to match appears unnecessarily complex. It is not simply a matter of bitwise AND-ing the addr with netmask after parsing?
Closing in favor of #6186.