Skip to content

Commit 8478d48

Browse files
committedMay 9, 2016
Add some warnings to std::env::current_exe
/cc rust-lang#21889
1 parent 0e7cb8b commit 8478d48

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
 

‎src/libstd/env.rs

+15
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,21 @@ 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+
/// This function should be used with care, as its incorrect usage can cause
499+
/// security problems. Specifically, as with many operations invovling files and
500+
/// paths, you can introduce a race condition. It goes like this:
501+
///
502+
/// 1. You get the path to the current executable using `current_exe()`, and
503+
/// store it in a variable binding.
504+
/// 2. Time passes. A malicious actor removes the current executable, and
505+
/// replaces it with a malicious one.
506+
/// 3. You then use the binding to try to open that file.
507+
///
508+
/// You expected to be opening the current executable, but you're now opening
509+
/// something completely different.
510+
///
496511
/// # Examples
497512
///
498513
/// ```

0 commit comments

Comments
 (0)