From: cheloha Date: Sat, 14 May 2022 14:52:20 +0000 (+0000) Subject: librthread: validate timespec inputs with timespecisvalid(3) X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=c554a768c1617ab8d979dfdbb7ffdf8827e11e8e;p=openbsd librthread: validate timespec inputs with timespecisvalid(3) ok millert@ --- diff --git a/lib/librthread/rthread_rwlock_compat.c b/lib/librthread/rthread_rwlock_compat.c index f9dc6f858b2..8c6e5cfa80f 100644 --- a/lib/librthread/rthread_rwlock_compat.c +++ b/lib/librthread/rthread_rwlock_compat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread_rwlock_compat.c,v 1.1 2019/02/13 13:15:39 mpi Exp $ */ +/* $OpenBSD: rthread_rwlock_compat.c,v 1.2 2022/05/14 14:52:20 cheloha Exp $ */ /* * Copyright (c) 2004,2005 Ted Unangst * Copyright (c) 2012 Philip Guenther @@ -143,8 +143,7 @@ int pthread_rwlock_timedrdlock(pthread_rwlock_t *lockp, const struct timespec *abstime) { - if (abstime == NULL || abstime->tv_nsec < 0 || - abstime->tv_nsec >= 1000000000) + if (abstime == NULL || !timespecisvalid(abstime)) return (EINVAL); return (_rthread_rwlock_rdlock(lockp, abstime, 0)); } @@ -210,8 +209,7 @@ int pthread_rwlock_timedwrlock(pthread_rwlock_t *lockp, const struct timespec *abstime) { - if (abstime == NULL || abstime->tv_nsec < 0 || - abstime->tv_nsec >= 1000000000) + if (abstime == NULL || !timespecisvalid(abstime)) return (EINVAL); return (_rthread_rwlock_wrlock(lockp, abstime, 0)); } diff --git a/lib/librthread/rthread_sem.c b/lib/librthread/rthread_sem.c index 172155ea12b..1bf189af453 100644 --- a/lib/librthread/rthread_sem.c +++ b/lib/librthread/rthread_sem.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread_sem.c,v 1.32 2020/04/06 00:01:08 pirofti Exp $ */ +/* $OpenBSD: rthread_sem.c,v 1.33 2022/05/14 14:52:20 cheloha Exp $ */ /* * Copyright (c) 2004,2005,2013 Ted Unangst * Copyright (c) 2018 Paul Irofti @@ -254,8 +254,7 @@ sem_timedwait(sem_t *semp, const struct timespec *abstime) int error; PREP_CANCEL_POINT(tib); - if (!semp || !(sem = *semp) || abstime == NULL || - abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000) { + if (!semp || !(sem = *semp) || !abstime || !timespecisvalid(abstime)) { errno = EINVAL; return (-1); } diff --git a/lib/librthread/rthread_sem_compat.c b/lib/librthread/rthread_sem_compat.c index 81309d5f28e..6800822b3f8 100644 --- a/lib/librthread/rthread_sem_compat.c +++ b/lib/librthread/rthread_sem_compat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread_sem_compat.c,v 1.1 2018/06/08 13:53:01 pirofti Exp $ */ +/* $OpenBSD: rthread_sem_compat.c,v 1.2 2022/05/14 14:52:20 cheloha Exp $ */ /* * Copyright (c) 2004,2005,2013 Ted Unangst * All Rights Reserved. @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -266,8 +267,7 @@ sem_timedwait(sem_t *semp, const struct timespec *abstime) int r; PREP_CANCEL_POINT(tib); - if (!semp || !(sem = *semp) || abstime == NULL || - abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000) { + if (!semp || !(sem = *semp) || !abstime || !timespecisvalid(abstime)) { errno = EINVAL; return (-1); }