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

NetworkAddress::IsInNetmask - broken address bits comparison #3684

Closed
DorpsGek opened this issue Mar 11, 2010 · 2 comments
Closed

NetworkAddress::IsInNetmask - broken address bits comparison #3684

DorpsGek opened this issue Mar 11, 2010 · 2 comments
Labels
flyspray This issue is imported from FlySpray (https://bugs.openttd.org/)

Comments

@DorpsGek
Copy link
Member

adf88 opened the ticket and wrote:

Inside NetworkAddress::IsInNetmask, when comparing bits of two addresses in 32-bit portions, pointers are not being advanced to next portion of bits thus only 32-bit address is compared properly. ++ operator is missing:

There is (network\core\address.cpp:164):
if ((*mask & msk) != (*ip & msk)) return false;

And should be:
if ((*mask++ & msk) != (*ip++ & msk)) return false;

Fix-patch attached.

By the way, few lines up (line 123), there is default mask length calculated as fallows:
int cidr = this->address.ss_family == AF_INET ? 32 : 128;
I think it would be nicer to take the length of address:
int cidr = this->address.address_length;

Attachments

Reported version: Version?
Operating system: All


This issue was imported from FlySpray: https://bugs.openttd.org/task/3684
@DorpsGek
Copy link
Member Author

Rubidium wrote:

If only the address_length was the actual length of the address in any sensible way; it's the sizeof of sockaddr_in/sockaddr_in6 which on my system are respectively 16 and 28.


This comment was imported from FlySpray: https://bugs.openttd.org/task/3684#comment7710

@DorpsGek
Copy link
Member Author

Rubidium closed the ticket.

Reason for closing: Fixed

In r19385


This comment was imported from FlySpray: https://bugs.openttd.org/task/3684

@DorpsGek DorpsGek added Core flyspray This issue is imported from FlySpray (https://bugs.openttd.org/) labels Apr 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flyspray This issue is imported from FlySpray (https://bugs.openttd.org/)
Projects
None yet
Development

No branches or pull requests

1 participant