libthread_xu/libc_r: Improve the check for EINVAL in sem_* functions.
authorSascha Wildner <saw@online.de>
Tue, 28 Feb 2012 22:44:29 +0000 (23:44 +0100)
committerSascha Wildner <saw@online.de>
Tue, 28 Feb 2012 22:44:29 +0000 (23:44 +0100)
Before referencing *sem->... in the check, do not just test if sem is
NULL but also if *sem is NULL.

Reported-by: Max Herrgard <herrgard@gmail.com>
lib/libc_r/uthread/uthread_sem.c
lib/libthread_xu/thread/thr_sem.c

index 1c6567f..76ed4fc 100644 (file)
@@ -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 <sys/semaphore.h>
@@ -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;                    \
index 80f5e1b..83768a1 100644 (file)
@@ -60,7 +60,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;