diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index f19bf33530..eaec04e787 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -1432,25 +1432,21 @@ int Process::sys$close(int fd) return rc; } -int Process::sys$utime(const char* pathname, const utimbuf* buf) +int Process::sys$utime(const char* user_path, size_t path_length, const utimbuf* user_buf) { - SmapDisabler disabler; - if (!validate_read_str(pathname)) + if (user_buf && !validate_read_typed(user_buf)) return -EFAULT; - if (buf && !validate_read_typed(buf)) - return -EFAULT; - time_t atime; - time_t mtime; - if (buf) { - atime = buf->actime; - mtime = buf->modtime; + auto path = get_syscall_path_argument(user_path, path_length); + if (path.is_error()) + return path.error(); + utimbuf buf; + if (user_buf) { + copy_from_user(&buf, user_buf, sizeof(buf)); } else { - struct timeval now; - kgettimeofday(now); - mtime = now.tv_sec; - atime = now.tv_sec; + auto now = kgettimeofday(); + buf = { now.tv_sec, now.tv_sec }; } - return VFS::the().utime(StringView(pathname), current_directory(), atime, mtime); + return VFS::the().utime(path.value(), current_directory(), buf.actime, buf.modtime); } int Process::sys$access(const char* user_path, size_t path_length, int mode) diff --git a/Kernel/Process.h b/Kernel/Process.h index 48faf6aaee..9c8f86a47c 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -176,7 +176,7 @@ public: int sys$ioctl(int fd, unsigned request, unsigned arg); int sys$mkdir(const char* pathname, size_t path_length, mode_t mode); clock_t sys$times(tms*); - int sys$utime(const char* pathname, const struct utimbuf*); + int sys$utime(const char* pathname, size_t path_length, const struct utimbuf*); int sys$link(const char* old_path, const char* new_path); int sys$unlink(const char* pathname); int sys$symlink(const char* target, const char* linkpath); diff --git a/Libraries/LibC/utime.cpp b/Libraries/LibC/utime.cpp index 761d2e60da..7b6955c071 100644 --- a/Libraries/LibC/utime.cpp +++ b/Libraries/LibC/utime.cpp @@ -1,12 +1,17 @@ #include #include +#include #include extern "C" { int utime(const char* pathname, const struct utimbuf* buf) { - int rc = syscall(SC_utime, (u32)pathname, (u32)buf); + if (!pathname) { + errno = EFAULT; + return -1; + } + int rc = syscall(SC_utime, pathname, strlen(pathname), buf); __RETURN_WITH_ERRNO(rc, rc, -1); } }