From 0ad9a640082f6a9f061b00ec6bf46d022de43532 Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Fri, 23 Sep 2022 19:43:25 +0200 Subject: [PATCH] fix: always set `directory` open flag in `open_ambient_dir` Signed-off-by: Roman Volosatovs --- cap-primitives/src/rustix/fs/dir_utils.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cap-primitives/src/rustix/fs/dir_utils.rs b/cap-primitives/src/rustix/fs/dir_utils.rs index bb18ee02..e706b199 100644 --- a/cap-primitives/src/rustix/fs/dir_utils.rs +++ b/cap-primitives/src/rustix/fs/dir_utils.rs @@ -6,7 +6,7 @@ use std::ops::Deref; #[cfg(unix)] use std::os::unix::{ffi::OsStrExt, fs::OpenOptionsExt}; #[cfg(target_os = "wasi")] -use std::os::wasi::ffi::OsStrExt; +use std::os::wasi::{ffi::OsStrExt, fs::OpenOptionsExt}; use std::path::Path; #[cfg(racy_asserts)] use std::{ffi::OsString, os::unix::ffi::OsStringExt, path::PathBuf}; @@ -100,15 +100,15 @@ pub(crate) fn canonicalize_options() -> OpenOptions { /// This function is not sandboxed and may trivially access any path that the /// host process has access to. pub(crate) fn open_ambient_dir_impl(path: &Path, _: AmbientAuthority) -> io::Result { - // This is for `std::fs`, so we don't have `dir_required`, so set - // `O_DIRECTORY` manually. - let flags = OFlags::DIRECTORY | target_o_path(); - let mut options = fs::OpenOptions::new(); options.read(true); #[cfg(not(target_os = "wasi"))] - options.custom_flags(flags.bits() as i32); + // This is for `std::fs`, so we don't have `dir_required`, so set + // `O_DIRECTORY` manually. + options.custom_flags((OFlags::DIRECTORY | target_o_path()).bits() as i32); + #[cfg(target_os = "wasi")] + options.directory(true); options.open(&path) }