From: Sascha Wildner Date: Tue, 28 Feb 2012 22:44:29 +0000 (+0100) Subject: libthread_xu/libc_r: Improve the check for EINVAL in sem_* functions. X-Git-Tag: v3.0.2~20 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/19b92a34330f1d18765aa08f4fb31cc97dcb50ed libthread_xu/libc_r: Improve the check for EINVAL in sem_* functions. Before referencing *sem->... in the check, do not just test if sem is NULL but also if *sem is NULL. Reported-by: Max Herrgard --- diff --git a/lib/libc_r/uthread/uthread_sem.c b/lib/libc_r/uthread/uthread_sem.c index 1c6567f55b..76ed4fcd7c 100644 --- a/lib/libc_r/uthread/uthread_sem.c +++ b/lib/libc_r/uthread/uthread_sem.c @@ -27,7 +27,6 @@ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/lib/libc_r/uthread/uthread_sem.c,v 1.3.2.5 2002/10/22 14:44:03 fjoe Exp $ - * $DragonFly: src/lib/libc_r/uthread/uthread_sem.c,v 1.4 2007/06/26 23:30:05 josepht Exp $ */ #include @@ -39,7 +38,8 @@ #include "pthread_private.h" #define _SEM_CHECK_VALIDITY(sem) \ - if ((*(sem))->magic != SEM_MAGIC) { \ + if ((sem) == NULL || *(sem) == NULL || \ + (*(sem))->magic != SEM_MAGIC) { \ errno = EINVAL; \ retval = -1; \ goto RETURN; \ diff --git a/lib/libthread_xu/thread/thr_sem.c b/lib/libthread_xu/thread/thr_sem.c index e14c8a37d5..c721569331 100644 --- a/lib/libthread_xu/thread/thr_sem.c +++ b/lib/libthread_xu/thread/thr_sem.c @@ -62,7 +62,7 @@ static inline int sem_check_validity(sem_t *sem) { - if ((sem != NULL) && ((*sem)->magic == SEM_MAGIC)) { + if ((sem != NULL) && (*sem != NULL) && ((*sem)->magic == SEM_MAGIC)) { return (0); } else { errno = EINVAL;