When checking for valid timevals in the wrapped select() and poll()

routines, don't return EINVAL but set errno to EINVAL and return -1.
Added a check in pthread_cond_timedwait for a null timespec pointer.
This commit is contained in:
Daniel Eischen 1999-08-30 00:02:08 +00:00
parent 293515f678
commit 3e12058d25
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=50601
9 changed files with 42 additions and 27 deletions

View File

@ -261,18 +261,20 @@ 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)
if (cond == NULL || abstime == NULL)
rval = EINVAL;
if (abstime->tv_sec < 0 ||
abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000) {
errno = EINVAL;
return (-1);
}
/*
* If the condition variable is statically initialized,
* perform the dynamic initialization:
*/
else if (*cond != NULL ||
if (*cond != NULL ||
(rval = pthread_cond_init(cond,NULL)) == 0) {
/* Lock the condition variable structure: */
_SPINLOCK(&(*cond)->lock);

View File

@ -67,7 +67,8 @@ poll(struct pollfd *fds, unsigned int nfds, int timeout)
_thread_kern_set_timeout(&ts);
} else if (timeout < 0) {
/* a timeout less than zero but not == INFTIM is invalid */
return (EINVAL);
errno = EINVAL;
return (-1);
}
if (((ret = _thread_sys_poll(fds, numfds, 0)) == 0) && (timeout != 0)) {

View File

@ -59,8 +59,10 @@ select(int numfds, fd_set * readfds, fd_set * writefds,
/* Check if a timeout was specified: */
if (timeout) {
if (timeout->tv_sec < 0 ||
timeout->tv_usec < 0 || timeout->tv_usec >= 1000000)
return (EINVAL);
timeout->tv_usec < 0 || timeout->tv_usec >= 1000000) {
errno = EINVAL;
return (-1);
}
/* Convert the timeval to a timespec: */
TIMEVAL_TO_TIMESPEC(timeout, &ts);

View File

@ -261,18 +261,20 @@ 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)
if (cond == NULL || abstime == NULL)
rval = EINVAL;
if (abstime->tv_sec < 0 ||
abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000) {
errno = EINVAL;
return (-1);
}
/*
* If the condition variable is statically initialized,
* perform the dynamic initialization:
*/
else if (*cond != NULL ||
if (*cond != NULL ||
(rval = pthread_cond_init(cond,NULL)) == 0) {
/* Lock the condition variable structure: */
_SPINLOCK(&(*cond)->lock);

View File

@ -67,7 +67,8 @@ poll(struct pollfd *fds, unsigned int nfds, int timeout)
_thread_kern_set_timeout(&ts);
} else if (timeout < 0) {
/* a timeout less than zero but not == INFTIM is invalid */
return (EINVAL);
errno = EINVAL;
return (-1);
}
if (((ret = _thread_sys_poll(fds, numfds, 0)) == 0) && (timeout != 0)) {

View File

@ -59,8 +59,10 @@ select(int numfds, fd_set * readfds, fd_set * writefds,
/* Check if a timeout was specified: */
if (timeout) {
if (timeout->tv_sec < 0 ||
timeout->tv_usec < 0 || timeout->tv_usec >= 1000000)
return (EINVAL);
timeout->tv_usec < 0 || timeout->tv_usec >= 1000000) {
errno = EINVAL;
return (-1);
}
/* Convert the timeval to a timespec: */
TIMEVAL_TO_TIMESPEC(timeout, &ts);

View File

@ -261,18 +261,20 @@ 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)
if (cond == NULL || abstime == NULL)
rval = EINVAL;
if (abstime->tv_sec < 0 ||
abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000) {
errno = EINVAL;
return (-1);
}
/*
* If the condition variable is statically initialized,
* perform the dynamic initialization:
*/
else if (*cond != NULL ||
if (*cond != NULL ||
(rval = pthread_cond_init(cond,NULL)) == 0) {
/* Lock the condition variable structure: */
_SPINLOCK(&(*cond)->lock);

View File

@ -67,7 +67,8 @@ poll(struct pollfd *fds, unsigned int nfds, int timeout)
_thread_kern_set_timeout(&ts);
} else if (timeout < 0) {
/* a timeout less than zero but not == INFTIM is invalid */
return (EINVAL);
errno = EINVAL;
return (-1);
}
if (((ret = _thread_sys_poll(fds, numfds, 0)) == 0) && (timeout != 0)) {

View File

@ -59,8 +59,10 @@ select(int numfds, fd_set * readfds, fd_set * writefds,
/* Check if a timeout was specified: */
if (timeout) {
if (timeout->tv_sec < 0 ||
timeout->tv_usec < 0 || timeout->tv_usec >= 1000000)
return (EINVAL);
timeout->tv_usec < 0 || timeout->tv_usec >= 1000000) {
errno = EINVAL;
return (-1);
}
/* Convert the timeval to a timespec: */
TIMEVAL_TO_TIMESPEC(timeout, &ts);