about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-07-20 00:48:21 -0700
committerGitHub <noreply@github.com>2016-07-20 00:48:21 -0700
commita63e3fac8fdf5187b155624aca622597ca9d344d (patch)
tree13c721e23f07cdaac60008e197887503d8a5fe36
parent48c245411b4a550bfe68e1a3eb703e8a22926402 (diff)
parentc4730daf450bafe51e76d430f94d2c59c814e53c (diff)
downloadrust-a63e3fac8fdf5187b155624aca622597ca9d344d.tar.gz
rust-a63e3fac8fdf5187b155624aca622597ca9d344d.zip
Auto merge of #33526 - steveklabnik:gh21889, r=alexcrichton
Add some warnings to std::env::current_exe

/cc #21889 @rust-lang/libs @semarie

I started writing this up. I'm not sure if we want to go into other things and in what depth; we don't currently have a lot of security-specific documentation to model after.

Thoughts?
-rw-r--r--src/libstd/env.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/libstd/env.rs b/src/libstd/env.rs
index 6956dc0d901..95aa6468dd9 100644
--- a/src/libstd/env.rs
+++ b/src/libstd/env.rs
@@ -493,6 +493,44 @@ pub fn temp_dir() -> PathBuf {
 /// that can fail for a good number of reasons. Some errors can include, but not
 /// be limited to, filesystem operations failing or general syscall failures.
 ///
+/// # Security
+///
+/// The output of this function should not be used in anything that might have
+/// security implications. For example:
+///
+/// ```
+/// fn main() {
+///     println!("{:?}", std::env::current_exe());
+/// }
+/// ```
+///
+/// On Linux systems, if this is compiled as `foo`:
+///
+/// ```bash
+/// $ rustc foo.rs
+/// $ ./foo
+/// Ok("/home/alex/foo")
+/// ```
+///
+/// And you make a symbolic link of the program:
+///
+/// ```bash
+/// $ ln foo bar
+/// ```
+///
+/// When you run it, you won't get the original executable, you'll get the
+/// symlink:
+///
+/// ```bash
+/// $ ./bar
+/// Ok("/home/alex/bar")
+/// ```
+///
+/// This sort of behavior has been known to [lead to privledge escalation] when
+/// used incorrectly, for example.
+///
+/// [lead to privledge escalation]: http://securityvulns.com/Wdocument183.html
+///
 /// # Examples
 ///
 /// ```