Repository navigation
address: refuse CIDR blocks too large to expand - #974
qianeric-backup wants to merge 1 commit into
Conversation
Expanding a CIDR block builds a `Vec<IpAddr>`, so a block that is too wide
does not fail politely - it takes the process down:
$ rustscan -a 2001:db8::/64 -p 80
thread 'main' panicked at library/alloc/src/raw_vec/mod.rs:28:5:
capacity overflow
$ rustscan -a 10.0.0.0/0 -p 1
memory allocation of 73014444032 bytes failed
The first asks for 2^64 entries and trips the allocator's own capacity check;
the second asks for 68 GiB at 16 bytes per address. Neither prints anything a
user can act on, and both are one command-line argument away.
The block size is now computed before any expansion, and a block wider than
`MAX_CIDR_ADDRESSES` is skipped with a message that says why:
$ rustscan -a 2001:db8::/64 -p 80
[!] Host "2001:db8::/64" spans 18446744073709551616 addresses, more than
the 16777216 RustScan expands; split the block up.
[!] No IPs could be resolved, aborting scan.
The limit is 2^24 addresses: 256 MiB of `IpAddr`, which keeps every IPv4 block
down to a /8 and every IPv6 block from /104 up, and is the constant to raise if
that turns out too tight.
Reporting it in the existing `unresolved_addresses` loop keeps `parse_address`'s
signature, and that loop now names the real cause instead of calling a valid
block "could not be resolved".
### Tests
Two unit tests in `src/address.rs`:
- `cidr_size_counts_addresses` covers /24, IPv4 /0, IPv6 /64 and `::/0`
(`1u128 << 128` would be a shift overflow, so that one is `u128::MAX`)
- `oversized_cidr_is_skipped_instead_of_aborting` parses both crashing targets
and asserts they come back empty
With the guard removed the second test panics with `capacity overflow`.
`cargo test` is 99 passed, `cargo clippy -- --deny warnings`,
`cargo clippy --tests -- --deny warnings` and `cargo fmt --check` on the file
are clean.
|
|
Note on the red The last run on
|



Expanding a CIDR block builds a
Vec<IpAddr>, so a block that is too wide does not fail politely – it takes the process down:The first asks for 2^64 entries, which trips the allocator's own capacity check; the second asks for 68 GiB at 16 bytes per address. Neither prints anything the user can act on, and both are one command-line argument away.
The block size is now computed before any expansion, and a block wider than
MAX_CIDR_ADDRESSESis skipped with a message that says why:The limit is 2^24 addresses – 256 MiB of
IpAddr. That keeps every IPv4 block down to a/8and every IPv6 block from/104up, and it is a single constant to raise if it turns out too tight.Reporting it in the existing
unresolved_addressesloop keepsparse_address's signature, and that loop now names the real cause instead of calling a valid block "could not be resolved".Tests
Two unit tests in
src/address.rs:cidr_size_counts_addressescovers/24, IPv4/0, IPv6/64and::/0(1u128 << 128would be a shift overflow, so that one isu128::MAX)oversized_cidr_is_skipped_instead_of_abortingparses both crashing targets and asserts they come back emptyWith the guard removed, the second test panics with
capacity overflow.cargo testis 99 passed, andcargo clippy -- --deny warnings,cargo clippy --tests -- --deny warningsandcargo fmt --checkon the file are clean.