Prohibit the use of unwrap() and increase Panics privacy!

Interesting information, I did some tests with rust 1.75, apparently it removes the sensitive part of the paths by default in release mode (only if no libraries(crate) are used).

Code :

fn main() {
    println!("Hello, world!");

    let str = "AAAA1000".to_string();
    let number = str.parse::<i32>().unwrap();

    print!("{}", number);
}

I'll use the linux command strings ./xxxx > str.txt to extract the strings contained in the final executable.

Cargo build --release :

I find this:

Cargo build :

I find this:

but, for example, if I add crates, this is what the release mode looks like (a more realistic project) :

use std::convert::Infallible;
use std::net::SocketAddr;

use bytes::Bytes;
use http_body_util::Full;
use hyper::server::conn::http1;
use hyper::service::service_fn;
use hyper::{Request, Response};
use hyper_util::rt::TokioIo;
use tokio::net::TcpListener;

async fn hello(_: Request<impl hyper::body::Body>) -> Result<Response<Full<Bytes>>, Infallible> {
    Ok(Response::new(Full::new(Bytes::from("Hello World!"))))
}

#[tokio::main]
pub async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
    pretty_env_logger::init();

    let addr: SocketAddr = ([127, 0, 0, 1], 3000).into();

    let listener = TcpListener::bind(addr).await?;
    println!("Listening on http://{}", addr);
    loop {
        let (tcp, _) = listener.accept().await?;

        let io = TokioIo::new(tcp);

        tokio::task::spawn(async move {
            if let Err(err) = http1::Builder::new()
                .serve_connection(io, service_fn(hello))
                .await
            {
                println!("Error serving connection: {:?}", err);
            }
        });
    }
}

Cargo build --release :

release2-1

You really can know almost everything about the code,

  • Project file structure
  • OS used and its version
  • Language used and compiler version
  • LLVM version
  • Developer's name
  • Crates used
  • Crates version (and easily deduce vulnerable crates)
  • The type of exception the application may be subject to
  • etc..

but there's another problem: there's too much useless data in release mode :

For embedded developers, with little memory available, it can still be optimized.

We need to review the management of error messages in Panics! in release mode, I think it's very dangerous to expose so much information. :face_with_raised_eyebrow:

and remove unnecessary information for a release ( eventually keep the Rust version for advertising purposes :laughing: )