fix(ParseIPRange): mask host bits in Network output for CIDR ranges - #2694
Open
n0liu wants to merge 1 commit into
Open
fix(ParseIPRange): mask host bits in Network output for CIDR ranges#2694n0liu wants to merge 1 commit into
n0liu wants to merge 1 commit into
Conversation
The 'Parse IP range' operation echoed the raw input address on the 'Network:' line for CIDR ranges instead of the network address. For '10.1.2.3/24' it printed 'Network: 10.1.2.3' rather than the masked 'Network: 10.1.2.0', even though the adjacent 'Range:' line and the IP-list code path already use the masked value. Use the masked address (ip1 = network & mask) for the IPv4 'Network:' line and the IPv6 'Network:' and 'Shorthand:' lines, matching the 'Range:' output in the same functions. Fixes gchq#1950
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.
Summary
Fixes #1950.
The Parse IP range operation printed the raw input address on the
Network:line for CIDR ranges instead of the network (masked) address.For input
10.1.2.3/24with "Include network info" enabled:The network address of
10.1.2.3/24is10.1.2.0(host bits masked off).Why this is a bug, not a preference
Within the very same function, the
Range:line already prints the masked value (ip1 = network & mask), and the operation's IP-list code path also prints the maskedNetwork:. Only the CIDR path echoed the unmasked input, so the operation was internally inconsistent. The IPv6 CIDR path had the identical issue on itsNetwork:andShorthand:lines (its hyphenated path already used the masked value).Fix
Use the masked address
ip1for:ipv4CidrRange—Network:ipv6CidrRange—Network:andShorthand:3 lines changed in
src/core/lib/IP.mjs; no behaviour change for inputs whose host bits are already zero.Tests
Added two cases to
tests/operations/tests/ParseIPRange.mjs(10.0.0.1/30and2404:6800:4001:0001::/48) whose inputs have host bits set. They fail on the current code (Network:echoes the unmasked input) and pass with the fix. Existing cases all use already-aligned addresses, so none previously exercised this.Full operations suite: 2282 passing / 0 failing (
npx grunt configTests && node --openssl-legacy-provider tests/operations/index.mjs), ESLint clean.