-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
TTL should be regarded as octal number (8-bit unsigned integer) #73158
Comments
Actually in this case,
Code: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=bfa7dfb16d218160b8758458cd68da21 [src/main.rs:4] socket.set_ttl(300) = Err(
Os {
code: 22,
kind: InvalidInput,
message: "Invalid argument",
},
) |
@lzutao interesting! I did not call |
I read the Unix code a bit. rust/src/libstd/sys_common/net.rs Lines 414 to 416 in feb3536
rust/src/libstd/sys_common/net.rs Lines 58 to 70 in feb3536
Maybe we could implement the check for ttl range in Rust side? But what are the advantages |
Also we might not be able to change the |
We can't change the parameter type because this is a stable API. Also, because you don't use the Result, you will get a warning:
|
@wesleywiser I understand it is a stable API. but taking |
One way to change the input type is to deprecate this function and introduce a new one with a correct type. |
I tried this code:
I expected to see this happen: I expected that it would raise compilation error because the
ttl
is octal and maximum value is 255. But I could set 300 as ttl.Instead, this happened: It does not raise any error and I could send packet with ttl more than 255. It was causing trouble as my software was setting ttl greater than 255 and was providing wrong data.
Upon looking more into the source code and documentation, it seems like
set_ttl
method is taking 32-bit unsigned integer typeu32
as ttl, where is should take 8-bit unsigned integer typeu8
as ttl.Meta
rustc --version --verbose
:Backtrace
The text was updated successfully, but these errors were encountered: