Skip to content

Commit a63e3fa

Browse files
authored
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?
2 parents 48c2454 + c4730da commit a63e3fa

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/libstd/env.rs

+38
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,44 @@ pub fn temp_dir() -> PathBuf {
493493
/// that can fail for a good number of reasons. Some errors can include, but not
494494
/// be limited to, filesystem operations failing or general syscall failures.
495495
///
496+
/// # Security
497+
///
498+
/// The output of this function should not be used in anything that might have
499+
/// security implications. For example:
500+
///
501+
/// ```
502+
/// fn main() {
503+
/// println!("{:?}", std::env::current_exe());
504+
/// }
505+
/// ```
506+
///
507+
/// On Linux systems, if this is compiled as `foo`:
508+
///
509+
/// ```bash
510+
/// $ rustc foo.rs
511+
/// $ ./foo
512+
/// Ok("/home/alex/foo")
513+
/// ```
514+
///
515+
/// And you make a symbolic link of the program:
516+
///
517+
/// ```bash
518+
/// $ ln foo bar
519+
/// ```
520+
///
521+
/// When you run it, you won't get the original executable, you'll get the
522+
/// symlink:
523+
///
524+
/// ```bash
525+
/// $ ./bar
526+
/// Ok("/home/alex/bar")
527+
/// ```
528+
///
529+
/// This sort of behavior has been known to [lead to privledge escalation] when
530+
/// used incorrectly, for example.
531+
///
532+
/// [lead to privledge escalation]: http://securityvulns.com/Wdocument183.html
533+
///
496534
/// # Examples
497535
///
498536
/// ```

0 commit comments

Comments
 (0)