diff options
| author | Steve Klabnik <steve@steveklabnik.com> | 2016-07-19 12:32:56 -0400 |
|---|---|---|
| committer | Steve Klabnik <steve@steveklabnik.com> | 2016-07-19 12:32:56 -0400 |
| commit | c4730daf450bafe51e76d430f94d2c59c814e53c (patch) | |
| tree | 42deedd87ae4a039e0adb897ab082083c5fd25c0 /src/libstd | |
| parent | 8478d48dad949b3b1374569a5391089a49094eeb (diff) | |
re-work example
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/env.rs | 47 |
1 files changed, 35 insertions, 12 deletions
diff --git a/src/libstd/env.rs b/src/libstd/env.rs index 369594e2b8f..5a3899eca3f 100644 --- a/src/libstd/env.rs +++ b/src/libstd/env.rs @@ -495,18 +495,41 @@ pub fn temp_dir() -> PathBuf { /// /// # Security /// -/// This function should be used with care, as its incorrect usage can cause -/// security problems. Specifically, as with many operations invovling files and -/// paths, you can introduce a race condition. It goes like this: -/// -/// 1. You get the path to the current executable using `current_exe()`, and -/// store it in a variable binding. -/// 2. Time passes. A malicious actor removes the current executable, and -/// replaces it with a malicious one. -/// 3. You then use the binding to try to open that file. -/// -/// You expected to be opening the current executable, but you're now opening -/// something completely different. +/// 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 /// |
