From 3c4b7dd55d34885dc50638bb0f7dd1a5061eebde Mon Sep 17 00:00:00 2001 From: 4lDO2 <4lDO2@protonmail.com> Date: Sat, 5 Apr 2025 17:13:50 +0200 Subject: [PATCH] Fix AsRef unsoundness for path syscalls. --- src/call.rs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/call.rs b/src/call.rs index fc1e900fd3..8bcc51d643 100644 --- a/src/call.rs +++ b/src/call.rs @@ -79,12 +79,13 @@ pub fn fpath(fd: usize, buf: &mut [u8]) -> Result { /// Rename a file pub fn frename>(fd: usize, path: T) -> Result { + let path = path.as_ref(); unsafe { syscall3( SYS_FRENAME, fd, - path.as_ref().as_ptr() as usize, - path.as_ref().len(), + path.as_ptr() as usize, + path.len(), ) } } @@ -246,11 +247,12 @@ pub fn nanosleep(req: &TimeSpec, rem: &mut TimeSpec) -> Result { /// Open a file pub fn open>(path: T, flags: usize) -> Result { + let path = path.as_ref(); unsafe { syscall3( SYS_OPEN, - path.as_ref().as_ptr() as usize, - path.as_ref().len(), + path.as_ptr() as usize, + path.len(), flags, ) } @@ -258,12 +260,13 @@ pub fn open>(path: T, flags: usize) -> Result { /// Open a file at a specific path pub fn openat>(fd: usize, path: T, flags: usize) -> Result { + let path = path.as_ref(); unsafe { syscall4( SYS_OPENAT, fd, - path.as_ref().as_ptr() as usize, - path.as_ref().len(), + path.as_ptr() as usize, + path.len(), flags, ) } @@ -276,11 +279,12 @@ pub fn read(fd: usize, buf: &mut [u8]) -> Result { /// Remove a directory pub fn rmdir>(path: T) -> Result { + let path = path.as_ref(); unsafe { syscall2( SYS_RMDIR, - path.as_ref().as_ptr() as usize, - path.as_ref().len(), + path.as_ptr() as usize, + path.len(), ) } } @@ -307,11 +311,12 @@ pub fn setreuid(ruid: usize, euid: usize) -> Result { /// Remove a file pub fn unlink>(path: T) -> Result { + let path = path.as_ref(); unsafe { syscall2( SYS_UNLINK, - path.as_ref().as_ptr() as usize, - path.as_ref().len(), + path.as_ptr() as usize, + path.len(), ) } }