From cf5249749d8577846680db6fa45e99618eb08f8b Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Mon, 9 Sep 2024 17:33:04 -0400 Subject: [PATCH] libbsd: Use timespec_to_bigtime for time conversions in kqueue. The FreeBSD manpage indicates that it will fail with EINVAL if an invalid timespec is passed. --- headers/private/libroot/time_private.h | 3 +-- src/libs/bsd/kqueue.cpp | 6 +++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/headers/private/libroot/time_private.h b/headers/private/libroot/time_private.h index c01fde2ed2..6e18d5b49d 100644 --- a/headers/private/libroot/time_private.h +++ b/headers/private/libroot/time_private.h @@ -11,9 +11,8 @@ #include #include -#include +#include -#include #define CLOCKS_PER_SEC_BEOS 1000 #define CLK_TCK_BEOS CLOCKS_PER_SEC_BEOS diff --git a/src/libs/bsd/kqueue.cpp b/src/libs/bsd/kqueue.cpp index 637bbf39fb..1800dea211 100644 --- a/src/libs/bsd/kqueue.cpp +++ b/src/libs/bsd/kqueue.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -187,7 +188,10 @@ kevent(int kq, bigtime_t timeout = 0; uint32 waitFlags = 0; if (tspec != NULL) { - timeout = (tspec->tv_sec * 1000000LL) + (tspec->tv_nsec / 1000LL); + if (!timespec_to_bigtime(*tspec, timeout)) { + __set_errno(EINVAL); + return -1; + } waitFlags |= B_RELATIVE_TIMEOUT; }