Kernel: Make access() take path+length

Also, let's return EFAULT for nullptr at the LibC layer. We can't do
all bad addresses this way, but we can at least do null. :^)
This commit is contained in:
Andreas Kling 2020-01-06 10:43:53 +01:00
parent ad4284428a
commit 642137f014
Notes: sideshowbarker 2024-07-19 10:19:04 +09:00
3 changed files with 10 additions and 6 deletions

View file

@ -1444,12 +1444,12 @@ int Process::sys$utime(const char* pathname, const utimbuf* buf)
return VFS::the().utime(StringView(pathname), current_directory(), atime, mtime);
}
int Process::sys$access(const char* pathname, int mode)
int Process::sys$access(const char* user_path, size_t path_length, int mode)
{
SmapDisabler disabler;
if (!validate_read_str(pathname))
if (!validate_read_str(user_path))
return -EFAULT;
return VFS::the().access(StringView(pathname), mode, current_directory());
auto path = copy_string_from_user(user_path, path_length);
return VFS::the().access(path, mode, current_directory());
}
int Process::sys$fcntl(int fd, int cmd, u32 arg)

View file

@ -171,7 +171,7 @@ public:
int sys$setgid(gid_t);
int sys$setuid(uid_t);
unsigned sys$alarm(unsigned seconds);
int sys$access(const char* pathname, int mode);
int sys$access(const char* pathname, size_t path_length, int mode);
int sys$fcntl(int fd, int cmd, u32 extra_arg);
int sys$ioctl(int fd, unsigned request, unsigned arg);
int sys$mkdir(const char* pathname, mode_t mode);

View file

@ -389,7 +389,11 @@ int setgid(uid_t gid)
int access(const char* pathname, int mode)
{
int rc = syscall(SC_access, pathname, mode);
if (!pathname) {
errno = EFAULT;
return -1;
}
int rc = syscall(SC_access, pathname, strlen(pathname), mode);
__RETURN_WITH_ERRNO(rc, rc, -1);
}