Stack information printed after rust causes panic

Hello everyone, I encountered a problem. I compiled the binary on one machine, and then when I ran it on another machine, the program panicked. When I printed the call stack information, the line of code where the panic occurred was: What is the path information of the machine when I compile the binary?

It looks like you forgot to include the code you wanted to show.

1 Like

Setting the environment variable RUST_BACKTRACE=1 can be helpful for getting it to print the full stack trace in many common cases.

If the reported line is too specific and unclear what is calling it, then check out:

https://doc.rust-lang.org/reference/attributes/codegen.html#the-track_caller-attribute

use strings my_binary | grep "$HOME will cause binary leakage

If you are looking to change the debuginfo so that it does not refer to a directory on your build machine, you can can pass the --remap-path-prefix argument to rustc.

For example, to replace your home directory path with the string "~", set this environment variable when running cargo build:

RUSTFLAGS="--remap-path-prefix $HOME=~"

There is also an unstable remap-cwd-prefix option that may be more convenient, after it's stabilized.

If I remap the path in the binary file, will it solve the problem of printing out the Home information when I panic?

Yes.

1 Like

The remap only applies to compiler-generated strings. That will solve your problem for panics, but it doesn't prevent you or some dependency from doing this, say.

const GOTTEM: &str = env!("HOME");
// Despite the name I used for this example, it's conceivable that
// some crate would do something like this for some HOME-containing
// environment variable non-maliciously, like storing some cargo env
// variable for telemetry blah blah blah something something when
// you have used rustup to install all the rust things in your HOME

Or more generally that information could be captured by build "scripts" that can currently do, well, pretty much anything they want.

So I suggest weighing how sure you want to be relative to how much trust you have in your dependencies.[1] If the remap isn't good enough for you after that consideration, do your development under an account with a generic name at a minimum.[2]


  1. both from a security and privacy-aware-acumen point of view ↩︎

  2. it shouldn't have access to any private information, really ↩︎

1 Like

Thanks very much!

thanks very much!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.