Skip to content

TTL should be regarded as octal number (8-bit unsigned integer) #73158

Open
@safwanrahman

Description

@safwanrahman

I tried this code:

use std::net::UdpSocket;
fn main(){
    let mut socket = UdpSocket::bind("0.0.0.0:1234").unwrap();
    socket.set_ttl(300);
}

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 type u32 as ttl, where is should take 8-bit unsigned integer type u8 as ttl.

Meta

rustc --version --verbose:

rustc 1.43.1 (8d69840ab 2020-05-04)
binary: rustc
commit-hash: 8d69840ab92ea7f4d323420088dd8c9775f180cd
commit-date: 2020-05-04
host: x86_64-apple-darwin
release: 1.43.1
LLVM version: 9.0
Backtrace

<backtrace>

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ioArea: `std::io`, `std::fs`, `std::net` and `std::path`C-bugCategory: This is a bug.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions