Skip to content
New issue

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

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

Already on GitHub? # to your account

Incorrect IP Address range calculation when using /0 prefix #484

Closed
mbcdev opened this issue Aug 18, 2022 · 2 comments
Closed

Incorrect IP Address range calculation when using /0 prefix #484

mbcdev opened this issue Aug 18, 2022 · 2 comments

Comments

@mbcdev
Copy link
Contributor

mbcdev commented Aug 18, 2022

It looks like IP address range calculations are not working correctly when using a /0 prefix.

Test Results (using 64-Bit Windows):

auto host_ip = Tins::IPv4Address("10.2.34.10");
auto zero_ip = Tins::IPv4Address("0.0.0.0");
auto zero_mask = Tins::IPv4Address("0.0.0.0");

auto range1 = Tins::IPv4Range::from_mask(zero_ip, zero_mask);
auto is_in_range1 = range1.contains(host_ip); // true (correct!)

auto range2 = Tins::IPv4Address(zero_ip) / 0;
auto is_in_range2 = range2.contains(host_ip); // false (wrong, should be true!)

auto range3 = Tins::IPv4Range::from_mask(zero_ip, Tins::IPv4Address::from_prefix_length(0));
auto is_in_range3 = range3.contains(host_ip); // false (wrong, should be true as well!)

auto mask0 = Tins::IPv4Address::from_prefix_length(0);
auto mask32 = Tins::IPv4Address::from_prefix_length(32);
auto is_equal = (mask0 == mask32); // true (wrong, should be false!)
mbcdev added a commit to mbcdev/libtins that referenced this issue Aug 26, 2022
…tanini#484)

According to the C/C++ Standard, for shift operations, the behavior is undefined if the right operand is equal to the width of the promoted left operand.
On a 64-bit Windows machine, this causes IP addresses 0.0.0.0 and 255.255.255.255 to have the same internal representation, leading to various issues when using a /0 prefix.
@mbcdev
Copy link
Contributor Author

mbcdev commented Aug 27, 2022

Reason:
According to the C/C++ Standard, for shift operations, the behavior is undefined if the right operand is equal to the width of the promoted left operand.
On a 64-bit Windows machine, this e.g. causes IP addresses 0.0.0.0 and 255.255.255.255 to have the same internal representation, leading to various issues when using a /0 prefix.

see #486 for fix proposal

mfontanini pushed a commit that referenced this issue Aug 30, 2022
#486)

According to the C/C++ Standard, for shift operations, the behavior is undefined if the right operand is equal to the width of the promoted left operand.
On a 64-bit Windows machine, this causes IP addresses 0.0.0.0 and 255.255.255.255 to have the same internal representation, leading to various issues when using a /0 prefix.
@mbcdev
Copy link
Contributor Author

mbcdev commented Oct 26, 2022

merged, closing issue

@mbcdev mbcdev closed this as completed Oct 26, 2022
laudrup pushed a commit to laudrup/libtins that referenced this issue Nov 23, 2022
…tanini#484) (mfontanini#486)

According to the C/C++ Standard, for shift operations, the behavior is undefined if the right operand is equal to the width of the promoted left operand.
On a 64-bit Windows machine, this causes IP addresses 0.0.0.0 and 255.255.255.255 to have the same internal representation, leading to various issues when using a /0 prefix.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant