Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix masking of irrelevant bits in address groups. #6556

Merged
merged 2 commits into from
Aug 20, 2015

Conversation

morcos
Copy link
Contributor

@morcos morcos commented Aug 14, 2015

If I'm reading this right, I believe the intent is to keep the high order nBits and mask away the others with 1's. But before this fix it was keeping the high order (8 - nBits). I don't think there was any effect, because the only time this was used was in the case of he.net /36 IPv6 groups so nBits was 4.

@sipa
Copy link
Member

sipa commented Aug 15, 2015

Nice catch. Changing the | into an & seems simpler, though.

@dcousens
Copy link
Contributor

Agreed, the & would be much clearer here and is more typical for a masking operation of this type.

@morcos
Copy link
Contributor Author

morcos commented Aug 17, 2015

I thought about & but I wasn't confident it was ok to change the previous behavior.
I also couldn't see how to make it as short?
vchRet.push_back(GetByte(15 - nStartByte) & (((1 << nBits) - 1) << (8 - nBits)));
or
vchRet.push_back(GetByte(15 - nStartByte) & ~((1 << (8-nBits)) - 1));

@sipa
Copy link
Member

sipa commented Aug 17, 2015

Good point, we shouldn't change the existing behaviour.

ACK

@jonasschnelli
Copy link
Contributor

utACK.
Would be nice if there would be test coverage in netbase_tests.cpp for this.

@laanwj
Copy link
Member

laanwj commented Aug 19, 2015

utACK.
There was a similar error in the netmask parsing.
Agree @jonasschnelli that unit tests for this function would be nice.

@morcos
Copy link
Contributor Author

morcos commented Aug 19, 2015

Ok writing unit test. I have a question about IsLocal(), since those addresses are also !IsRoutable() they will be lumped in the NET_UNROUTABLE group instead of having their own group. The check for IsLocal() on line 932 is meaningless. Is that expected? Changing that would obviously change existing behavior.

@laanwj
Copy link
Member

laanwj commented Aug 20, 2015

Yes, that check seems to be redundant. But let's leave removing it for another pull.

Thanks for adding tests.

@laanwj laanwj merged commit 1123cdb into bitcoin:master Aug 20, 2015
laanwj added a commit that referenced this pull request Aug 20, 2015
1123cdb add unit test for CNetAddr::GetGroup. (Alex Morcos)
bba3db1 Fix masking of irrelevant bits in address groups. (Alex Morcos)
@laanwj laanwj added the Bug label Aug 20, 2015
furszy added a commit to PIVX-Project/PIVX that referenced this pull request May 21, 2020
5d7887e add unit test for CNetAddr::GetGroup. (Alex Morcos)
f0e0aca Fix masking of irrelevant bits in address groups. (Alex Morcos)

Pull request description:

  Backport of bitcoin#6556

  Original description:

  > If I'm reading this right, I believe the intent is to keep the high order nBits and mask away the others with 1's. But before this fix it was keeping the high order (8 - nBits). I don't think there was any effect, because the only time this was used was in the case of he.net /36 IPv6 groups so nBits was 4.

ACKs for top commit:
  random-zebra:
    utACK 5d7887e
  furszy:
    utACK 5d7887e

Tree-SHA512: 8cc095561918c838b46dd7b957ab5a7acc8788fa568b760157f026e012bada4d6dc5b7f6c4b2dfc58dc3f05382237bb265c61cc4c76175aff9341dafeea567e8
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
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.

5 participants