From b26885fbc1a42b3fb148f9ecca460714670af116 Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Thu, 11 Aug 2022 10:33:58 +0200 Subject: [PATCH] Fixed a potential issue when renaming a file and the destination is from a preopened dir and already exist (for #3084) --- lib/wasi/src/syscalls/mod.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 51f7595f20c..0c5266e6efc 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -2656,6 +2656,18 @@ pub fn path_rename( source_path.to_str().as_ref().unwrap(), true )); + if state + .fs + .get_inode_at_path( + inodes.deref_mut(), + new_fd, + target_path.to_str().as_ref().unwrap(), + true, + ) + .is_ok() + { + return __WASI_EEXIST; + } let (source_parent_inode, source_entry_name) = wasi_try!(state .fs