Re: librthread: validate timespec inputs with timespecisvalid(3)

2022-05-14 Thread Todd C . Miller
On Sat, 14 May 2022 09:31:26 -0500, Scott Cheloha wrote:

> ok?

OK millert@

 - todd



librthread: validate timespec inputs with timespecisvalid(3)

2022-05-14 Thread Scott Cheloha
ok?

Index: rthread_rwlock_compat.c
===
RCS file: /cvs/src/lib/librthread/rthread_rwlock_compat.c,v
retrieving revision 1.1
diff -u -p -r1.1 rthread_rwlock_compat.c
--- rthread_rwlock_compat.c 13 Feb 2019 13:15:39 -  1.1
+++ rthread_rwlock_compat.c 14 May 2022 14:29:27 -
@@ -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 >= 10)
+   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 >= 10)
+   if (abstime == NULL || !timespecisvalid(abstime))
return (EINVAL);
return (_rthread_rwlock_wrlock(lockp, abstime, 0));
 }
Index: rthread_sem.c
===
RCS file: /cvs/src/lib/librthread/rthread_sem.c,v
retrieving revision 1.32
diff -u -p -r1.32 rthread_sem.c
--- rthread_sem.c   6 Apr 2020 00:01:08 -   1.32
+++ rthread_sem.c   14 May 2022 14:29:27 -
@@ -254,8 +254,7 @@ sem_timedwait(sem_t *semp, const struct 
int error;
PREP_CANCEL_POINT(tib);
 
-   if (!semp || !(sem = *semp) || abstime == NULL ||
-  abstime->tv_nsec < 0 || abstime->tv_nsec >= 10) {
+   if (!semp || !(sem = *semp) || !abstime || !timespecisvalid(abstime)) {
errno = EINVAL;
return (-1);
}
Index: rthread_sem_compat.c
===
RCS file: /cvs/src/lib/librthread/rthread_sem_compat.c,v
retrieving revision 1.1
diff -u -p -r1.1 rthread_sem_compat.c
--- rthread_sem_compat.c8 Jun 2018 13:53:01 -   1.1
+++ rthread_sem_compat.c14 May 2022 14:29:27 -
@@ -19,6 +19,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -266,8 +267,7 @@ sem_timedwait(sem_t *semp, const struct 
int r;
PREP_CANCEL_POINT(tib);
 
-   if (!semp || !(sem = *semp) || abstime == NULL ||
-   abstime->tv_nsec < 0 || abstime->tv_nsec >= 10) {
+   if (!semp || !(sem = *semp) || !abstime || !timespecisvalid(abstime)) {
errno = EINVAL;
return (-1);
}