Skip to content
Merged
Changes from all commits
Commits
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
10 changes: 4 additions & 6 deletions src/uucore/src/lib/features/safe_traversal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use std::path::{Path, PathBuf};
use nix::dir::Dir;
use nix::fcntl::{OFlag, openat};
use nix::libc;
use nix::sys::stat::{FchmodatFlags, FileStat, Mode, fchmodat, fstatat};
use nix::sys::stat::{FchmodatFlags, FileStat, Mode, fchmodat, fstatat, mkdirat};
use nix::unistd::{Gid, Uid, UnlinkatFlags, fchown, fchownat, unlinkat};
use os_display::Quotable;

Expand Down Expand Up @@ -323,12 +323,10 @@ impl DirFd {
pub fn mkdir_at(&self, name: &OsStr, mode: u32) -> io::Result<()> {
let name_cstr =
CString::new(name.as_bytes()).map_err(|_| SafeTraversalError::PathContainsNull)?;
let mode = mode as libc::mode_t;
let fd = self.fd.as_raw_fd();
let mode = Mode::from_bits_truncate(mode as libc::mode_t);

let result = unsafe { libc::mkdirat(fd, name_cstr.as_ptr(), mode) };
if result == -1 {
let err = io::Error::last_os_error();
if let Err(e) = mkdirat(self.fd.as_fd(), name_cstr.as_c_str(), mode) {
let err = io::Error::from_raw_os_error(e as i32);
return Err(SafeTraversalError::OpenFailed {
path: name.into(),
source: err,
Expand Down
Loading