Skip to content
Open
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
19 changes: 19 additions & 0 deletions api/ruxos_posix_api/src/imp/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ pub fn sys_open(filename: *const c_char, flags: c_int, mode: ctypes::mode_t) ->
/// Open a file under a specific dir
pub fn sys_openat(fd: c_int, path: *const c_char, flags: c_int, mode: ctypes::mode_t) -> c_int {
syscall_body!(sys_openat, {
let raw_path = char_ptr_to_path_str(path)?;
if raw_path.is_empty() {
return Err(LinuxError::ENOENT);
}
let path = parse_path_at(fd, path)?;
validate_path_components(&path)?;
let flags = OpenFlags::from_bits(flags).ok_or(LinuxError::EINVAL)?;
debug!("sys_openat <= fd {fd} {path:?}, {flags:?}, {mode:#o}");
let mode = FilePerm::from_bits_truncate(mode as u16 & !get_umask());
Expand Down Expand Up @@ -742,6 +747,20 @@ pub fn parse_path_at(dirfd: c_int, path: *const c_char) -> LinuxResult<AbsPath<'
}
}

const MAX_NAME_LEN: usize = 64;

fn validate_path_components(path: &AbsPath<'static>) -> LinuxResult {
for component in path.as_str().split('/') {
if component.is_empty() {
continue;
}
if component.len() > MAX_NAME_LEN {
return Err(LinuxError::ENAMETOOLONG);
}
}
Ok(())
}

fn file_from_fd(fd: i32) -> LinuxResult<Arc<File>> {
get_file_like(fd)?
.into_any()
Expand Down
Loading