Ipv4Addr: Incorrect Parsing for Octal format IP string #83648
Labels
C-bug
Category: This is a bug.
T-libs-api
Relevant to the library API team, which will review and decide on the PR/issue.
Uh oh!
There was an error while loading. Please reload this page.
This issue is inspired by this blog.
Due to the specification, leading zero in IP string is interpreted as octal literals. So a IP address
0127.0.0.1
actually means87.0.0.1
. As shown in the following example:However, the
Ipv4Addr
from the std library will recognize it as127.0.0.1
instead. A simple code to demo the situation (playground link):I expected to see this happen:
Instead, this happened:
Noted this bug may cause security vulnerabilities in certain cases. For example, a Rust program uses
Ipv4Addr
doing some sanity check then passing the user string to other library or program.Furthermore, the specification actually also allows hex format in IP string.
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: