-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Some valid IPv4 addresses are not parsed by Ipv4Addr::from_str() #90199
Comments
This is intentional for security purposes. As the documentation says:
Which links to the section of RFC 6943 which describes strict parsing of IPv4 literals. |
That not for security reason, it's just a ambiguous syntax, and nobody use it. Ipv6 The security in doc is for octal confusion like |
The doc is a bit incomplete/imprecise IMHO as the section of the RFC defines a strict and loose form. We should reword it thus:
|
This makes the tests pass again on nightly, and avoids using legacy IP while we have glorious IPv6 support everywhere nowadays. See also rust-lang/rust#90199
Note that the current implementation leaves open the possibility of incorrectly considering a string not to be an IPv4 address literal when it actually is one. Imagine if this were used in validation code to prevent connections to raw IP addresses: it could easily offer a validation bypass since low-level networking functions will happily connect to it. |
Tbh, I personally think this is just a documentation bug. Rust has chosen to use only the strict form when parsing. We should be clearer about documenting that and also document any caveats that people should be aware of. |
Encountering this right now and the doc is most definitely flawed. Not sure what was up with the dislike for OP bringing it to our attention |
An IPv4 address is usually represented by four decimal numbers separated by a dot, but this isn’t the only allowed representation. Most programs support alternative representations with fewer dots where the last number is either 16-bit, 24-bit, or 32-bit, see the manpage of
inet_aton()
. In order to be compatible with these programs and users’ assumptions,std::net::Ipv4Addr
should add support for these formats.I tried this code:
I expected to see this happen: nothing, as the parsing would succeed and then the assert would pass.
Instead, this happened: thread 'main' panicked at 'called
Result::unwrap()
on anErr
value: AddrParseError(())', src/main.rs:3:47Meta
rustc --version --verbose
:Backtrace
The text was updated successfully, but these errors were encountered: