mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 04:09:13 +00:00
Kernel: Implement 'copy_time_from_user' functions to sanitize arguments
This commit is contained in:
parent
bd6be910e5
commit
649abc01bc
Notes:
sideshowbarker
2024-07-18 21:48:14 +09:00
Author: https://github.com/BenWiederhake
Commit: 649abc01bc
Pull-request: https://github.com/SerenityOS/serenity/pull/5323
Reviewed-by: https://github.com/ADKaster
Reviewed-by: https://github.com/awesomekling
Reviewed-by: https://github.com/bgianfo
2 changed files with 32 additions and 0 deletions
|
@ -63,6 +63,32 @@ String copy_string_from_user(Userspace<const char*> user_str, size_t user_str_si
|
|||
return copy_string_from_user(user_str.unsafe_userspace_ptr(), user_str_size);
|
||||
}
|
||||
|
||||
[[nodiscard]] Optional<Time> copy_time_from_user(const timespec* ts_user)
|
||||
{
|
||||
timespec ts;
|
||||
if (!copy_from_user(&ts, ts_user, sizeof(timespec))) {
|
||||
return {};
|
||||
}
|
||||
return Time::from_timespec(ts);
|
||||
}
|
||||
[[nodiscard]] Optional<Time> copy_time_from_user(const timeval* tv_user)
|
||||
{
|
||||
timeval tv;
|
||||
if (!copy_from_user(&tv, tv_user, sizeof(timeval))) {
|
||||
return {};
|
||||
}
|
||||
return Time::from_timeval(tv);
|
||||
}
|
||||
|
||||
template<>
|
||||
[[nodiscard]] Optional<Time> copy_time_from_user<const timeval>(Userspace<const timeval*> src) { return copy_time_from_user(src.unsafe_userspace_ptr()); }
|
||||
template<>
|
||||
[[nodiscard]] Optional<Time> copy_time_from_user<timeval>(Userspace<timeval*> src) { return copy_time_from_user(src.unsafe_userspace_ptr()); }
|
||||
template<>
|
||||
[[nodiscard]] Optional<Time> copy_time_from_user<const timespec>(Userspace<const timespec*> src) { return copy_time_from_user(src.unsafe_userspace_ptr()); }
|
||||
template<>
|
||||
[[nodiscard]] Optional<Time> copy_time_from_user<timespec>(Userspace<timespec*> src) { return copy_time_from_user(src.unsafe_userspace_ptr()); }
|
||||
|
||||
Optional<u32> user_atomic_fetch_add_relaxed(volatile u32* var, u32 val)
|
||||
{
|
||||
if (FlatPtr(var) & 3)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue