diff options
author | jasone <jasone@FreeBSD.org> | 2000-07-17 22:55:05 +0000 |
---|---|---|
committer | jasone <jasone@FreeBSD.org> | 2000-07-17 22:55:05 +0000 |
commit | fa7c7acbf98a1fc07bfb99c6781d96fe9fa83830 (patch) | |
tree | f09ec81f26b43fd3c62eb02bfbc9423a2a04f58b /lib/libc_r | |
parent | 29b66ff09c91b62fdbd8b207fc418abd1ed0cf74 (diff) | |
download | FreeBSD-src-fa7c7acbf98a1fc07bfb99c6781d96fe9fa83830.zip FreeBSD-src-fa7c7acbf98a1fc07bfb99c6781d96fe9fa83830.tar.gz |
Deal correctly with statically initialized condition variables in
pthread_cond_signal(), pthread_cond_broadcast(), and pthread_cond_timedwait().
Do not dump core in pthread_cond_timedwait() (due to a NULL pointer
dereference) if attempting to wait on an uninitialized condition variable.
PR: bin/18099
Diffstat (limited to 'lib/libc_r')
-rw-r--r-- | lib/libc_r/uthread/uthread_cond.c | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/lib/libc_r/uthread/uthread_cond.c b/lib/libc_r/uthread/uthread_cond.c index 49062be..4c18465 100644 --- a/lib/libc_r/uthread/uthread_cond.c +++ b/lib/libc_r/uthread/uthread_cond.c @@ -305,23 +305,14 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex, _thread_enter_cancellation_point(); - if (cond == NULL || abstime == NULL) + if (abstime == NULL || abstime->tv_sec < 0 || abstime->tv_nsec < 0 || + abstime->tv_nsec >= 1000000000) rval = EINVAL; - - if (abstime->tv_sec < 0 || - abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000) { - errno = EINVAL; - _thread_leave_cancellation_point(); - return (-1); - } - /* - * If the condition variable is statically initialized, - * perform the dynamic initialization: + * If the condition variable is statically initialized, perform dynamic + * initialization. */ - if (*cond != NULL || - (rval = pthread_cond_init(cond,NULL)) == 0) { - + else if (*cond != NULL || (rval = pthread_cond_init(cond, NULL)) == 0) { _thread_enter_cancellation_point(); /* Lock the condition variable structure: */ @@ -471,9 +462,13 @@ pthread_cond_signal(pthread_cond_t * cond) int rval = 0; pthread_t pthread; - if (cond == NULL || *cond == NULL) + if (cond == NULL) rval = EINVAL; - else { + /* + * If the condition variable is statically initialized, perform dynamic + * initialization. + */ + else if (*cond != NULL || (rval = pthread_cond_init(cond, NULL) == 0)) { /* * Defer signals to protect the scheduling queues * from access by the signal handler: @@ -532,9 +527,13 @@ pthread_cond_broadcast(pthread_cond_t * cond) int rval = 0; pthread_t pthread; - if (cond == NULL || *cond == NULL) + if (cond == NULL) rval = EINVAL; - else { + /* + * If the condition variable is statically initialized, perform dynamic + * initialization. + */ + else if (*cond != NULL || (rval = pthread_cond_init(cond, NULL) == 0)) { /* * Defer signals to protect the scheduling queues * from access by the signal handler: |