Skip to content

Commit

Permalink
fix unsafe
Browse files Browse the repository at this point in the history
Signed-off-by: yihuaf <[email protected]>
  • Loading branch information
yihuaf committed May 11, 2023
1 parent 5ac716a commit 415dee8
Showing 1 changed file with 7 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::utils::test_inside_container;
use anyhow::{anyhow, Context};
use anyhow::Context;
use nix::libc;
use nix::mount::{mount, umount, MsFlags};
use nix::sys::stat::Mode;
Expand Down Expand Up @@ -548,19 +548,14 @@ fn check_recursive_rnosymfollow() -> TestResult {
);
let result = test_inside_container(spec, &|_| {
let original_file_path = format!("{}/{}", rnosymfollow_dir_path.to_str().unwrap(), "file");
File::create(original_file_path.clone())?;
let file = File::create(&original_file_path)?;
let link_file_path = format!("{}/{}", rnosymfollow_dir_path.to_str().unwrap(), "link");
println!("original file: {original_file_path:?},link file: {link_file_path:?}");
let mode = libc::S_ISUID | libc::S_ISGID;
let result = unsafe {
libc::chmod(
original_file_path.as_ptr() as *const ::std::os::raw::c_char,
mode,
)
};
if result == -1 {
return Err(anyhow!(std::io::Error::last_os_error()));
};
let mut permission = file.metadata()?.permissions();
permission.set_mode(permission.mode() | libc::S_ISUID | libc::S_ISGID);
file.set_permissions(permission)
.with_context(|| "failed to set permission")?;

symlink(original_file_path, link_file_path)?;
println!("symlink success");
Ok(())
Expand Down

0 comments on commit 415dee8

Please sign in to comment.