Skip to content

Rollup of 13 pull requests #93119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 40 commits into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
763703c
Remove redundant check for promoteds
tmiasko Oct 11, 2021
d5a91f3
Use `IndexVec::indices` instead of reimplementing it
tmiasko Oct 11, 2021
c3e71d8
Fix a variant index and variant discriminant confusion
tmiasko Oct 11, 2021
cd626fe
Stabilize -Z print-link-args as --print link-args
joshtriplett Dec 6, 2021
371bd46
Document `--print link-args`
joshtriplett Dec 6, 2021
36a1141
Make message for &T -> &mut T transmute more accurate
5225225 Jan 9, 2022
dc1c39b
rustdoc: decouple stability and const-stability
euclio Dec 9, 2021
c280752
Help optimize out backtraces when disabled
kornelski Jan 17, 2022
a8b7116
change `ct_infer` to a delay_span_bug
lcnr Jan 5, 2022
621e60a
remove unnecessary fixme
lcnr Jan 5, 2022
b2d8f0c
generic_arg_infer: placeholder in signature err
lcnr Jan 5, 2022
cbc6d35
privacy: update `visit_infer`
lcnr Jan 10, 2022
217458b
intra-doc links
lcnr Jan 17, 2022
29a2d6b
intra-doc: Use the impl's assoc item where possible
camelid Jan 8, 2022
2938be6
Correctly handle starts in block doc comments
GuillaumeGomez Jan 18, 2022
06b00ad
Add test for block doc comments
GuillaumeGomez Jan 18, 2022
5ab67bf
Fix CVE-2022-21658 for Windows
ChrisDenton Jan 6, 2022
54e22eb
Fix CVE-2022-21658 for UNIX-like
hkratz Dec 18, 2021
cb748a2
Fix CVE-2022-21658 for WASI
alexcrichton Jan 4, 2022
32080ad
Update std::fs::remove_dir_all documentation
pietroalbini Jan 19, 2022
5c96dcf
Add MaybeUninit::as_bytes
Amanieu Oct 10, 2021
6487845
Properly account for binders in get_impl_future_output_ty
tmandry Dec 21, 2021
5c15ad7
NiceRegionError: Use written return type for async fn
tmandry Nov 20, 2021
698631e
Simplify error reporting code, remove await point wording
tmandry Dec 10, 2021
152e888
Rustdoc mobile: put out-of-band on its own line
jsha Jan 13, 2022
3b10045
:arrow_up: rust-analyzer
lnicola Jan 20, 2022
0a6c9ad
Fix compilation for a few tier 2 targets
hkratz Jan 20, 2022
98cb338
Rollup merge of #89747 - Amanieu:maybeuninit_bytes, r=m-ou-se
matthiaskrgr Jan 20, 2022
d188287
Rollup merge of #89764 - tmiasko:uninhabited-enums, r=wesleywiser
matthiaskrgr Jan 20, 2022
02379e9
Rollup merge of #91606 - joshtriplett:stabilize-print-link-args, r=pn…
matthiaskrgr Jan 20, 2022
405cf20
Rollup merge of #91694 - euclio:stability-improvements, r=GuillaumeGomez
matthiaskrgr Jan 20, 2022
413f490
Rollup merge of #92183 - tmandry:issue-74256, r=estebank
matthiaskrgr Jan 20, 2022
db1253f
Rollup merge of #92582 - lcnr:generic-arg-infer, r=BoxyUwU
matthiaskrgr Jan 20, 2022
1839829
Rollup merge of #92680 - camelid:assoc-item-cleanup, r=petrochenkov
matthiaskrgr Jan 20, 2022
5c10dbd
Rollup merge of #92704 - 5225225:std_mem_transmute_ref_t_mut_t, r=mic…
matthiaskrgr Jan 20, 2022
ed3bf67
Rollup merge of #92861 - jsha:mobile-column-flex, r=GuillaumeGomez
matthiaskrgr Jan 20, 2022
1cb57e2
Rollup merge of #92992 - kornelski:backtraceopt, r=Mark-Simulacrum
matthiaskrgr Jan 20, 2022
6c627d2
Rollup merge of #93038 - GuillaumeGomez:block-doc-comments, r=notriddle
matthiaskrgr Jan 20, 2022
d893b0a
Rollup merge of #93108 - lnicola:rust-analyzer-2022-01-20, r=lnicola
matthiaskrgr Jan 20, 2022
dbc9749
Rollup merge of #93112 - pietroalbini:pa-cve-2022-21658-nightly, r=pi…
matthiaskrgr Jan 20, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions library/std/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2042,13 +2042,17 @@ pub fn remove_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
///
/// # Platform-specific behavior
///
/// This function currently corresponds to `opendir`, `lstat`, `rm` and `rmdir` functions on Unix
/// and the `FindFirstFile`, `GetFileAttributesEx`, `DeleteFile`, and `RemoveDirectory` functions
/// on Windows.
/// Note that, this [may change in the future][changes].
/// This function currently corresponds to `openat`, `fdopendir`, `unlinkat` and `lstat` functions
/// on Unix (except for macOS before version 10.10 and REDOX) and the `CreateFileW`,
/// `GetFileInformationByHandleEx`, `SetFileInformationByHandle`, and `NtOpenFile` functions on
/// Windows. Note that, this [may change in the future][changes].
///
/// [changes]: io#platform-specific-behavior
///
/// On macOS before version 10.10 and REDOX this function is not protected against time-of-check to
/// time-of-use (TOCTOU) race conditions, and should not be used in security-sensitive code on
/// those platforms. All other platforms are protected.
///
/// # Errors
///
/// See [`fs::remove_file`] and [`fs::remove_dir`].
Expand Down
70 changes: 70 additions & 0 deletions library/std/src/fs/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ use crate::fs::{self, File, OpenOptions};
use crate::io::{ErrorKind, SeekFrom};
use crate::path::Path;
use crate::str;
use crate::sync::Arc;
use crate::sys_common::io::test::{tmpdir, TempDir};
use crate::thread;
use crate::time::{Duration, Instant};

use rand::{rngs::StdRng, RngCore, SeedableRng};

Expand Down Expand Up @@ -601,6 +603,21 @@ fn recursive_rmdir_of_symlink() {
assert!(canary.exists());
}

#[test]
fn recursive_rmdir_of_file_fails() {
// test we do not delete a directly specified file.
let tmpdir = tmpdir();
let canary = tmpdir.join("do_not_delete");
check!(check!(File::create(&canary)).write(b"foo"));
let result = fs::remove_dir_all(&canary);
#[cfg(unix)]
error!(result, "Not a directory");
#[cfg(windows)]
error!(result, 267); // ERROR_DIRECTORY - The directory name is invalid.
assert!(result.is_err());
assert!(canary.exists());
}

#[test]
// only Windows makes a distinction between file and directory symlinks.
#[cfg(windows)]
Expand All @@ -620,6 +637,59 @@ fn recursive_rmdir_of_file_symlink() {
}
}

#[test]
#[ignore] // takes too much time
fn recursive_rmdir_toctou() {
// Test for time-of-check to time-of-use issues.
//
// Scenario:
// The attacker wants to get directory contents deleted, to which he does not have access.
// He has a way to get a privileged Rust binary call `std::fs::remove_dir_all()` on a
// directory he controls, e.g. in his home directory.
//
// The POC sets up the `attack_dest/attack_file` which the attacker wants to have deleted.
// The attacker repeatedly creates a directory and replaces it with a symlink from
// `victim_del` to `attack_dest` while the victim code calls `std::fs::remove_dir_all()`
// on `victim_del`. After a few seconds the attack has succeeded and
// `attack_dest/attack_file` is deleted.
let tmpdir = tmpdir();
let victim_del_path = tmpdir.join("victim_del");
let victim_del_path_clone = victim_del_path.clone();

// setup dest
let attack_dest_dir = tmpdir.join("attack_dest");
let attack_dest_dir = attack_dest_dir.as_path();
fs::create_dir(attack_dest_dir).unwrap();
let attack_dest_file = tmpdir.join("attack_dest/attack_file");
File::create(&attack_dest_file).unwrap();

let drop_canary_arc = Arc::new(());
let drop_canary_weak = Arc::downgrade(&drop_canary_arc);

eprintln!("x: {:?}", &victim_del_path);

// victim just continuously removes `victim_del`
thread::spawn(move || {
while drop_canary_weak.upgrade().is_some() {
let _ = fs::remove_dir_all(&victim_del_path_clone);
}
});

// attacker (could of course be in a separate process)
let start_time = Instant::now();
while Instant::now().duration_since(start_time) < Duration::from_secs(1000) {
if !attack_dest_file.exists() {
panic!(
"Victim deleted symlinked file outside of victim_del. Attack succeeded in {:?}.",
Instant::now().duration_since(start_time)
);
}
let _ = fs::create_dir(&victim_del_path);
let _ = fs::remove_dir(&victim_del_path);
let _ = symlink_dir(attack_dest_dir, &victim_del_path);
}
}

#[test]
fn unicode_path_is_dir() {
assert!(Path::new(".").is_dir());
Expand Down
Loading