Skip to content

fix(ParseIPRange): mask host bits in Network output for CIDR ranges - #2694

Open
n0liu wants to merge 1 commit into
gchq:masterfrom
n0liu:fix/parse-ip-range-network-mask
Open

fix(ParseIPRange): mask host bits in Network output for CIDR ranges#2694
n0liu wants to merge 1 commit into
gchq:masterfrom
n0liu:fix/parse-ip-range-network-mask

Conversation

@n0liu

@n0liu n0liu commented Jul 25, 2026

Copy link
Copy Markdown

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/24 with "Include network info" enabled:

Network: 10.1.2.3          <-- wrong: echoes the input host address
CIDR: 24
Mask: 255.255.255.0
Range: 10.1.2.0 - 10.1.2.255

The network address of 10.1.2.3/24 is 10.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 masked Network:. Only the CIDR path echoed the unmasked input, so the operation was internally inconsistent. The IPv6 CIDR path had the identical issue on its Network: and Shorthand: lines (its hyphenated path already used the masked value).

Fix

Use the masked address ip1 for:

  • ipv4CidrRangeNetwork:
  • ipv6CidrRangeNetwork: and Shorthand:

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/30 and 2404: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.

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
@CLAassistant

CLAassistant commented Jul 25, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug report: Wrong Network output in Parse IP Range recipe.

2 participants