T8374: convert addresses to the host byte order before comparison in IPv4 range checks#21
Merged
jestabro merged 1 commit intovyos:currentfrom Mar 11, 2026
Merged
Conversation
when checking that the lower boundary of an IPv4 range is actually lower than the upper bound
jestabro
approved these changes
Mar 11, 2026
Contributor
jestabro
left a comment
There was a problem hiding this comment.
Fix obvious (in hindsight) bug; test added to confirm.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The original logic didn't account for the fact that
in_addr->s_addris stored in the network by order (big endian) and shouldn't be compared directly without byte order conversion on little-endian architectures.That made certain checks like
ipaddrcheck --verbose --is-ipv4-range 192.0.2.0-1.8.2.1succeed, but the issue remained hidden because the comparison logic issue didn't affect more common bad ranges like192.0.2.200-192.0.2.100.In my defense, the POSIX docs for
netinet/in.hdoesn't say anything about the order and at the time I didn't realize the conversion happens much earlier than I thought.Note that the IPv6 comparison logic is byte-by-byte from the start of the array, so it wasn't susceptible to that issue:
Change Summary
Types of changes
Related Task(s)
Related PR(s)
Proposed changes
How to test
Checklist: