libroot: check timeout interval parameter in ppoll(), pselect() and select()
* also introduce timeval_to_bigtime * time_private is c++ only Change-Id: I2bddbe5f95240735c7b42ccf429dcbb3f1e8bb1b Reviewed-on: https://review.haiku-os.org/c/haiku/+/5220 Tested-by: Commit checker robot <[email protected]> Reviewed-by: waddlesplash <[email protected]> Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
committed by
Adrien Destugues
parent
30294b6d05
commit
eb22dbd032
@@ -67,6 +67,14 @@ timeval_to_timespec(const timeval& val, timespec& spec)
|
||||
}
|
||||
|
||||
|
||||
static inline bool
|
||||
timeval_to_bigtime(const timeval& val, bigtime_t& _time)
|
||||
{
|
||||
timespec spec;
|
||||
return timeval_to_timespec(val, spec) && timespec_to_bigtime(spec, _time);
|
||||
}
|
||||
|
||||
|
||||
static inline void
|
||||
timespec_to_timeval(const timespec& spec, timeval& val)
|
||||
{
|
||||
|
||||
@@ -52,7 +52,7 @@ KernelMergeObject kernel_lib_posix.o :
|
||||
kernel_errno.cpp
|
||||
dirent.c
|
||||
fcntl.cpp
|
||||
poll.c
|
||||
poll.cpp
|
||||
utime.c
|
||||
# locale
|
||||
ctype.cpp
|
||||
@@ -77,7 +77,7 @@ KernelMergeObject kernel_lib_posix.o :
|
||||
chmod.c
|
||||
stat.c
|
||||
mkdir.c
|
||||
select.c
|
||||
select.cpp
|
||||
gettimeofday.c
|
||||
uio.c
|
||||
# time
|
||||
|
||||
@@ -29,7 +29,7 @@ for architectureObject in [ MultiArchSubDirSetup ] {
|
||||
inttypes.c
|
||||
libgen.cpp
|
||||
nftw.c
|
||||
poll.c
|
||||
poll.cpp
|
||||
$(PWD_BACKEND)
|
||||
scheduler.cpp
|
||||
semaphore.cpp
|
||||
|
||||
@@ -13,9 +13,10 @@
|
||||
|
||||
#include <errno_private.h>
|
||||
#include <syscalls.h>
|
||||
#include <time_private.h>
|
||||
|
||||
|
||||
int __ppoll(struct pollfd *fds, nfds_t numfds, const struct timespec *tv,
|
||||
extern "C" int __ppoll(struct pollfd *fds, nfds_t numfds, const struct timespec *tv,
|
||||
const sigset_t *sigMask);
|
||||
|
||||
int
|
||||
@@ -32,8 +33,8 @@ __ppoll(struct pollfd *fds, nfds_t numfds, const struct timespec *tv,
|
||||
{
|
||||
int status;
|
||||
bigtime_t timeout = -1LL;
|
||||
if (tv)
|
||||
timeout = tv->tv_sec * 1000000LL + tv->tv_nsec / 1000LL;
|
||||
if (tv != NULL && !timespec_to_bigtime(*tv, timeout))
|
||||
RETURN_AND_SET_ERRNO_TEST_CANCEL(EINVAL);
|
||||
|
||||
status = _kern_poll(fds, numfds, timeout, sigMask);
|
||||
|
||||
@@ -23,7 +23,7 @@ for architectureObject in [ MultiArchSubDirSetup ] {
|
||||
mman.cpp
|
||||
priority.c
|
||||
rlimit.c
|
||||
select.c
|
||||
select.cpp
|
||||
stat.c
|
||||
statvfs.c
|
||||
times.cpp
|
||||
|
||||
@@ -13,16 +13,16 @@
|
||||
#include <syscall_utils.h>
|
||||
|
||||
#include <errno_private.h>
|
||||
#include <signal_private.h>
|
||||
#include <symbol_versioning.h>
|
||||
#include <syscalls.h>
|
||||
|
||||
#include <signal_private.h>
|
||||
#include <time_private.h>
|
||||
|
||||
|
||||
int __pselect_beos(int numBits, struct fd_set *readBits,
|
||||
extern "C" int __pselect_beos(int numBits, struct fd_set *readBits,
|
||||
struct fd_set *writeBits, struct fd_set *errorBits,
|
||||
const struct timespec *tv, const sigset_t *beosSignalMask);
|
||||
int __pselect(int numBits, struct fd_set *readBits, struct fd_set *writeBits,
|
||||
extern "C" int __pselect(int numBits, struct fd_set *readBits, struct fd_set *writeBits,
|
||||
struct fd_set *errorBits, const struct timespec *tv,
|
||||
const sigset_t *sigMask);
|
||||
|
||||
@@ -35,8 +35,8 @@ __pselect_beos(int numBits, struct fd_set *readBits, struct fd_set *writeBits,
|
||||
int status;
|
||||
sigset_t signalMask;
|
||||
bigtime_t timeout = -1LL;
|
||||
if (tv)
|
||||
timeout = tv->tv_sec * 1000000LL + tv->tv_nsec / 1000LL;
|
||||
if (tv != NULL && !timespec_to_bigtime(*tv, timeout))
|
||||
RETURN_AND_SET_ERRNO_TEST_CANCEL(EINVAL);
|
||||
|
||||
if (beosSignalMask != NULL)
|
||||
signalMask = from_beos_sigset(*beosSignalMask);
|
||||
@@ -55,8 +55,8 @@ __pselect(int numBits, struct fd_set *readBits, struct fd_set *writeBits,
|
||||
{
|
||||
int status;
|
||||
bigtime_t timeout = -1LL;
|
||||
if (tv)
|
||||
timeout = tv->tv_sec * 1000000LL + tv->tv_nsec / 1000LL;
|
||||
if (tv != NULL && !timespec_to_bigtime(*tv, timeout))
|
||||
RETURN_AND_SET_ERRNO_TEST_CANCEL(EINVAL);
|
||||
|
||||
status = _kern_select(numBits, readBits, writeBits, errorBits, timeout,
|
||||
sigMask);
|
||||
@@ -71,8 +71,8 @@ select(int numBits, struct fd_set *readBits, struct fd_set *writeBits,
|
||||
{
|
||||
int status;
|
||||
bigtime_t timeout = -1LL;
|
||||
if (tv)
|
||||
timeout = tv->tv_sec * 1000000LL + tv->tv_usec;
|
||||
if (tv != NULL && !timeval_to_bigtime(*tv, timeout))
|
||||
RETURN_AND_SET_ERRNO_TEST_CANCEL(EINVAL);
|
||||
|
||||
status = _kern_select(numBits, readBits, writeBits, errorBits, timeout,
|
||||
NULL);
|
||||
Reference in New Issue
Block a user