Skip to content

fix: handle non-canonical CIDR notation where host bits are set#899

Open
Nicceboy wants to merge 1 commit intobee-san:masterfrom
Nicceboy:fix-noncanonical-cidr
Open

fix: handle non-canonical CIDR notation where host bits are set#899
Nicceboy wants to merge 1 commit intobee-san:masterfrom
Nicceboy:fix-noncanonical-cidr

Conversation

@Nicceboy
Copy link
Copy Markdown

Problem

RustScan fails silently when a CIDR is given where the input IP has host bits set (i.e. the IP is not the network address for that prefix).

rustscan -a 192.168.1.13/29
[!] Host "192.168.1.13/29" could not be resolved.
[!] No IPs could be resolved, aborting scan.

This is valid and common input. Users naturally provide their known host IP with a subnet mask to mean "scan this subnet". Tools like nmap accept it without complaint.

What currently happens:

  1. IpInet::from_str("192.168.1.13/29") rejects it — host bits 101 in .13 are non-zero
  2. Falls through to DNS resolution, which also fails
  3. Address is treated as a file path, which also fails
  4. A misleading "could not be resolved" warning is shown

Fix

Adds a normalize_cidr helper that masks off the host bits to derive the true network address before parsing. 192.168.1.13/29 becomes 192.168.1.8/29 (.13 = 0000 1101 → mask last 3 bits → .8 = 0000 1000), which is then expanded to the expected 8 addresses.

The change is one helper function and one additional else if branch in parse_address.

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.

1 participant