Skip to content

Commit 67e3a2b

Browse files
Rollup merge of #46987 - frewsxcv:frewsxcv-current-exe, r=QuietMisdreavus
Minor rewrite of env::current_exe docs; clarify symlinks. - Update example in ‘security’ section to use hard links, like the linked securityvulns.com example. - Weaken language on symbolic links – indicate behavior is platform-specific Fixes #43617.
2 parents b98fd52 + 17380f2 commit 67e3a2b

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/libstd/env.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -571,8 +571,11 @@ pub fn temp_dir() -> PathBuf {
571571

572572
/// Returns the full filesystem path of the current running executable.
573573
///
574-
/// The path returned is not necessarily a "real path" of the executable as
575-
/// there may be intermediate symlinks.
574+
/// # Platform-specific behavior
575+
///
576+
/// If the executable was invoked through a symbolic link, some platforms will
577+
/// return the path of the symbolic link and other platforms will return the
578+
/// path of the symbolic link’s target.
576579
///
577580
/// # Errors
578581
///
@@ -599,24 +602,24 @@ pub fn temp_dir() -> PathBuf {
599602
/// Ok("/home/alex/foo")
600603
/// ```
601604
///
602-
/// And you make a symbolic link of the program:
605+
/// And you make a hard link of the program:
603606
///
604607
/// ```bash
605608
/// $ ln foo bar
606609
/// ```
607610
///
608-
/// When you run it, you won't get the original executable, you'll get the
609-
/// symlink:
611+
/// When you run it, you wont get the path of the original executable, you’ll
612+
/// get the path of the hard link:
610613
///
611614
/// ```bash
612615
/// $ ./bar
613616
/// Ok("/home/alex/bar")
614617
/// ```
615618
///
616619
/// This sort of behavior has been known to [lead to privilege escalation] when
617-
/// used incorrectly, for example.
620+
/// used incorrectly.
618621
///
619-
/// [lead to privilege escalation]: http://securityvulns.com/Wdocument183.html
622+
/// [lead to privilege escalation]: https://securityvulns.com/Wdocument183.html
620623
///
621624
/// # Examples
622625
///
@@ -625,7 +628,7 @@ pub fn temp_dir() -> PathBuf {
625628
///
626629
/// match env::current_exe() {
627630
/// Ok(exe_path) => println!("Path of this executable is: {}",
628-
/// exe_path.display()),
631+
/// exe_path.display()),
629632
/// Err(e) => println!("failed to get current exe path: {}", e),
630633
/// };
631634
/// ```

0 commit comments

Comments
 (0)