diff options
author | Alfred Perlstein <alfred@FreeBSD.org> | 1999-08-19 23:06:11 +0000 |
---|---|---|
committer | Alfred Perlstein <alfred@FreeBSD.org> | 1999-08-19 23:06:11 +0000 |
commit | 91518882e0644ea4047cdeffbed637e857906caa (patch) | |
tree | b10bd9f64c914d3351cce2d7847b7bc1f73b2c5a /lib | |
parent | d3c6699913165313c0a4b2a03e7e068ede6c7384 (diff) | |
download | src-91518882e0644ea4047cdeffbed637e857906caa.tar.gz src-91518882e0644ea4047cdeffbed637e857906caa.zip |
Sanity check time structures passed in, return EINVAL like the system
calls do to avoid corrupting the thread library's concept of wakeup
time.
PR: kern/12141
Reviewed by: deischen, eivind
Notes
Notes:
svn path=/head/; revision=50065
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc_r/uthread/uthread_cond.c | 6 | ||||
-rw-r--r-- | lib/libc_r/uthread/uthread_nanosleep.c | 5 | ||||
-rw-r--r-- | lib/libc_r/uthread/uthread_poll.c | 7 | ||||
-rw-r--r-- | lib/libc_r/uthread/uthread_select.c | 6 | ||||
-rw-r--r-- | lib/libkse/thread/thr_cond.c | 6 | ||||
-rw-r--r-- | lib/libkse/thread/thr_nanosleep.c | 5 | ||||
-rw-r--r-- | lib/libkse/thread/thr_poll.c | 7 | ||||
-rw-r--r-- | lib/libkse/thread/thr_select.c | 6 | ||||
-rw-r--r-- | lib/libpthread/thread/thr_cond.c | 6 | ||||
-rw-r--r-- | lib/libpthread/thread/thr_nanosleep.c | 5 | ||||
-rw-r--r-- | lib/libpthread/thread/thr_poll.c | 7 | ||||
-rw-r--r-- | lib/libpthread/thread/thr_select.c | 6 |
12 files changed, 54 insertions, 18 deletions
diff --git a/lib/libc_r/uthread/uthread_cond.c b/lib/libc_r/uthread/uthread_cond.c index bacfb7217337..4d52c631dcdc 100644 --- a/lib/libc_r/uthread/uthread_cond.c +++ b/lib/libc_r/uthread/uthread_cond.c @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id$ + * $Id: uthread_cond.c,v 1.15 1999/06/20 08:28:13 jb Exp $ */ #include <stdlib.h> #include <errno.h> @@ -261,6 +261,10 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex, int rval = 0; int status; + if (abstime->tv_sec < 0 || + abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000) + return (EINVAL); + if (cond == NULL) rval = EINVAL; diff --git a/lib/libc_r/uthread/uthread_nanosleep.c b/lib/libc_r/uthread/uthread_nanosleep.c index dd82efd99717..1a1e1739053a 100644 --- a/lib/libc_r/uthread/uthread_nanosleep.c +++ b/lib/libc_r/uthread/uthread_nanosleep.c @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id$ + * $Id: uthread_nanosleep.c,v 1.7 1999/08/05 12:15:18 deischen Exp $ */ #include <stdio.h> #include <errno.h> @@ -48,7 +48,8 @@ nanosleep(const struct timespec * time_to_sleep, struct timeval tv; /* Check if the time to sleep is legal: */ - if (time_to_sleep == NULL || time_to_sleep->tv_nsec < 0 || time_to_sleep->tv_nsec > 1000000000) { + if (time_to_sleep == NULL || time_to_sleep->tv_sec < 0 || + time_to_sleep->tv_nsec < 0 || time_to_sleep->tv_nsec > 1000000000) { /* Return an EINVAL error : */ errno = EINVAL; ret = -1; diff --git a/lib/libc_r/uthread/uthread_poll.c b/lib/libc_r/uthread/uthread_poll.c index a54d0236f5f6..2acd725dea5f 100644 --- a/lib/libc_r/uthread/uthread_poll.c +++ b/lib/libc_r/uthread/uthread_poll.c @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id$ + * $Id: uthread_poll.c,v 1.1 1999/06/20 08:28:36 jb Exp $ */ #include <unistd.h> #include <errno.h> @@ -58,13 +58,16 @@ poll(struct pollfd *fds, unsigned int nfds, int timeout) if (timeout == INFTIM) { /* Wait for ever: */ _thread_kern_set_timeout(NULL); - } else if (timeout != 0) { + } else if (timeout > 0) { /* Convert the timeout in msec to a timespec: */ ts.tv_sec = timeout / 1000; ts.tv_nsec = (timeout % 1000) * 1000; /* Set the wake up time: */ _thread_kern_set_timeout(&ts); + } else if (timeout < 0) { + /* a timeout less than zero but not == INFTIM is invalid */ + return (EINVAL); } if (((ret = _thread_sys_poll(fds, numfds, 0)) == 0) && (timeout != 0)) { diff --git a/lib/libc_r/uthread/uthread_select.c b/lib/libc_r/uthread/uthread_select.c index 67de75d33f47..2042fde4ac56 100644 --- a/lib/libc_r/uthread/uthread_select.c +++ b/lib/libc_r/uthread/uthread_select.c @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: uthread_select.c,v 1.8 1999/06/23 15:01:22 dt Exp $ + * $Id: uthread_select.c,v 1.9 1999/08/05 12:15:21 deischen Exp $ */ #include <unistd.h> #include <errno.h> @@ -53,6 +53,10 @@ select(int numfds, fd_set * readfds, fd_set * writefds, int pfd_index, got_one = 0, fd_count = 0; struct pthread_poll_data data; + if (timeout->tv_sec < 0 || + timeout->tv_usec < 0 || timeout->tv_usec >= 1000000) + return (EINVAL); + if (numfds > _thread_dtablesize) { numfds = _thread_dtablesize; } diff --git a/lib/libkse/thread/thr_cond.c b/lib/libkse/thread/thr_cond.c index bacfb7217337..4d52c631dcdc 100644 --- a/lib/libkse/thread/thr_cond.c +++ b/lib/libkse/thread/thr_cond.c @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id$ + * $Id: uthread_cond.c,v 1.15 1999/06/20 08:28:13 jb Exp $ */ #include <stdlib.h> #include <errno.h> @@ -261,6 +261,10 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex, int rval = 0; int status; + if (abstime->tv_sec < 0 || + abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000) + return (EINVAL); + if (cond == NULL) rval = EINVAL; diff --git a/lib/libkse/thread/thr_nanosleep.c b/lib/libkse/thread/thr_nanosleep.c index dd82efd99717..1a1e1739053a 100644 --- a/lib/libkse/thread/thr_nanosleep.c +++ b/lib/libkse/thread/thr_nanosleep.c @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id$ + * $Id: uthread_nanosleep.c,v 1.7 1999/08/05 12:15:18 deischen Exp $ */ #include <stdio.h> #include <errno.h> @@ -48,7 +48,8 @@ nanosleep(const struct timespec * time_to_sleep, struct timeval tv; /* Check if the time to sleep is legal: */ - if (time_to_sleep == NULL || time_to_sleep->tv_nsec < 0 || time_to_sleep->tv_nsec > 1000000000) { + if (time_to_sleep == NULL || time_to_sleep->tv_sec < 0 || + time_to_sleep->tv_nsec < 0 || time_to_sleep->tv_nsec > 1000000000) { /* Return an EINVAL error : */ errno = EINVAL; ret = -1; diff --git a/lib/libkse/thread/thr_poll.c b/lib/libkse/thread/thr_poll.c index a54d0236f5f6..2acd725dea5f 100644 --- a/lib/libkse/thread/thr_poll.c +++ b/lib/libkse/thread/thr_poll.c @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id$ + * $Id: uthread_poll.c,v 1.1 1999/06/20 08:28:36 jb Exp $ */ #include <unistd.h> #include <errno.h> @@ -58,13 +58,16 @@ poll(struct pollfd *fds, unsigned int nfds, int timeout) if (timeout == INFTIM) { /* Wait for ever: */ _thread_kern_set_timeout(NULL); - } else if (timeout != 0) { + } else if (timeout > 0) { /* Convert the timeout in msec to a timespec: */ ts.tv_sec = timeout / 1000; ts.tv_nsec = (timeout % 1000) * 1000; /* Set the wake up time: */ _thread_kern_set_timeout(&ts); + } else if (timeout < 0) { + /* a timeout less than zero but not == INFTIM is invalid */ + return (EINVAL); } if (((ret = _thread_sys_poll(fds, numfds, 0)) == 0) && (timeout != 0)) { diff --git a/lib/libkse/thread/thr_select.c b/lib/libkse/thread/thr_select.c index 67de75d33f47..2042fde4ac56 100644 --- a/lib/libkse/thread/thr_select.c +++ b/lib/libkse/thread/thr_select.c @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: uthread_select.c,v 1.8 1999/06/23 15:01:22 dt Exp $ + * $Id: uthread_select.c,v 1.9 1999/08/05 12:15:21 deischen Exp $ */ #include <unistd.h> #include <errno.h> @@ -53,6 +53,10 @@ select(int numfds, fd_set * readfds, fd_set * writefds, int pfd_index, got_one = 0, fd_count = 0; struct pthread_poll_data data; + if (timeout->tv_sec < 0 || + timeout->tv_usec < 0 || timeout->tv_usec >= 1000000) + return (EINVAL); + if (numfds > _thread_dtablesize) { numfds = _thread_dtablesize; } diff --git a/lib/libpthread/thread/thr_cond.c b/lib/libpthread/thread/thr_cond.c index bacfb7217337..4d52c631dcdc 100644 --- a/lib/libpthread/thread/thr_cond.c +++ b/lib/libpthread/thread/thr_cond.c @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id$ + * $Id: uthread_cond.c,v 1.15 1999/06/20 08:28:13 jb Exp $ */ #include <stdlib.h> #include <errno.h> @@ -261,6 +261,10 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex, int rval = 0; int status; + if (abstime->tv_sec < 0 || + abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000) + return (EINVAL); + if (cond == NULL) rval = EINVAL; diff --git a/lib/libpthread/thread/thr_nanosleep.c b/lib/libpthread/thread/thr_nanosleep.c index dd82efd99717..1a1e1739053a 100644 --- a/lib/libpthread/thread/thr_nanosleep.c +++ b/lib/libpthread/thread/thr_nanosleep.c @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id$ + * $Id: uthread_nanosleep.c,v 1.7 1999/08/05 12:15:18 deischen Exp $ */ #include <stdio.h> #include <errno.h> @@ -48,7 +48,8 @@ nanosleep(const struct timespec * time_to_sleep, struct timeval tv; /* Check if the time to sleep is legal: */ - if (time_to_sleep == NULL || time_to_sleep->tv_nsec < 0 || time_to_sleep->tv_nsec > 1000000000) { + if (time_to_sleep == NULL || time_to_sleep->tv_sec < 0 || + time_to_sleep->tv_nsec < 0 || time_to_sleep->tv_nsec > 1000000000) { /* Return an EINVAL error : */ errno = EINVAL; ret = -1; diff --git a/lib/libpthread/thread/thr_poll.c b/lib/libpthread/thread/thr_poll.c index a54d0236f5f6..2acd725dea5f 100644 --- a/lib/libpthread/thread/thr_poll.c +++ b/lib/libpthread/thread/thr_poll.c @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id$ + * $Id: uthread_poll.c,v 1.1 1999/06/20 08:28:36 jb Exp $ */ #include <unistd.h> #include <errno.h> @@ -58,13 +58,16 @@ poll(struct pollfd *fds, unsigned int nfds, int timeout) if (timeout == INFTIM) { /* Wait for ever: */ _thread_kern_set_timeout(NULL); - } else if (timeout != 0) { + } else if (timeout > 0) { /* Convert the timeout in msec to a timespec: */ ts.tv_sec = timeout / 1000; ts.tv_nsec = (timeout % 1000) * 1000; /* Set the wake up time: */ _thread_kern_set_timeout(&ts); + } else if (timeout < 0) { + /* a timeout less than zero but not == INFTIM is invalid */ + return (EINVAL); } if (((ret = _thread_sys_poll(fds, numfds, 0)) == 0) && (timeout != 0)) { diff --git a/lib/libpthread/thread/thr_select.c b/lib/libpthread/thread/thr_select.c index 67de75d33f47..2042fde4ac56 100644 --- a/lib/libpthread/thread/thr_select.c +++ b/lib/libpthread/thread/thr_select.c @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: uthread_select.c,v 1.8 1999/06/23 15:01:22 dt Exp $ + * $Id: uthread_select.c,v 1.9 1999/08/05 12:15:21 deischen Exp $ */ #include <unistd.h> #include <errno.h> @@ -53,6 +53,10 @@ select(int numfds, fd_set * readfds, fd_set * writefds, int pfd_index, got_one = 0, fd_count = 0; struct pthread_poll_data data; + if (timeout->tv_sec < 0 || + timeout->tv_usec < 0 || timeout->tv_usec >= 1000000) + return (EINVAL); + if (numfds > _thread_dtablesize) { numfds = _thread_dtablesize; } |