Module Name:    src
Committed By:   kamil
Date:           Wed Jan 29 15:07:46 UTC 2020

Modified Files:
        src/lib/libpthread: pthread_cond.c

Log Message:
Use pthread_condattr_t and pthread_cond_t magic fields

Validate _PT_CONDATTR_MAGIC and _PT_COND_MAGIC respectively.


To generate a diff of this commit:
cvs rdiff -u -r1.66 -r1.67 src/lib/libpthread/pthread_cond.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libpthread/pthread_cond.c
diff -u src/lib/libpthread/pthread_cond.c:1.66 src/lib/libpthread/pthread_cond.c:1.67
--- src/lib/libpthread/pthread_cond.c:1.66	Mon Jan 13 18:22:56 2020
+++ src/lib/libpthread/pthread_cond.c	Wed Jan 29 15:07:46 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_cond.c,v 1.66 2020/01/13 18:22:56 ad Exp $	*/
+/*	$NetBSD: pthread_cond.c,v 1.67 2020/01/29 15:07:46 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -46,7 +46,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: pthread_cond.c,v 1.66 2020/01/13 18:22:56 ad Exp $");
+__RCSID("$NetBSD: pthread_cond.c,v 1.67 2020/01/29 15:07:46 kamil Exp $");
 
 #include <stdlib.h>
 #include <errno.h>
@@ -78,6 +78,10 @@ __strong_alias(__libc_cond_destroy,pthre
 static clockid_t
 pthread_cond_getclock(const pthread_cond_t *cond)
 {
+
+	pthread__error(EINVAL, "Invalid condition variable",
+	    cond->ptc_magic == _PT_COND_MAGIC);
+
 	return cond->ptc_private ? 
 	    *(clockid_t *)cond->ptc_private : CLOCK_REALTIME;
 }
@@ -222,9 +226,6 @@ pthread__cond_wake_one(pthread_cond_t *c
 	pthread_mutex_t *mutex;
 	lwpid_t lid;
 
-	pthread__error(EINVAL, "Invalid condition variable",
-	    cond->ptc_magic == _PT_COND_MAGIC);
-
 	/*
 	 * Pull the first thread off the queue.  If the current thread
 	 * is associated with the condition variable, remove it without
@@ -278,6 +279,9 @@ pthread_cond_signal(pthread_cond_t *cond
 	if (__predict_false(__uselibcstub))
 		return __libc_cond_signal_stub(cond);
 
+	pthread__error(EINVAL, "Invalid condition variable",
+	    cond->ptc_magic == _PT_COND_MAGIC);
+
 	if (__predict_true(PTQ_EMPTY(&cond->ptc_waiters)))
 		return 0;
 	return pthread__cond_wake_one(cond);
@@ -291,9 +295,6 @@ pthread__cond_wake_all(pthread_cond_t *c
 	u_int max;
 	size_t nwaiters;
 
-	pthread__error(EINVAL, "Invalid condition variable",
-	    cond->ptc_magic == _PT_COND_MAGIC);
-
 	/*
 	 * Try to defer waking threads (see pthread_cond_signal()).
 	 * Only transfer waiters for which there is no pending wakeup.
@@ -328,6 +329,9 @@ pthread_cond_broadcast(pthread_cond_t *c
 	if (__predict_false(__uselibcstub))
 		return __libc_cond_broadcast_stub(cond);
 
+	pthread__error(EINVAL, "Invalid condition variable",
+	    cond->ptc_magic == _PT_COND_MAGIC);
+
 	if (__predict_true(PTQ_EMPTY(&cond->ptc_waiters)))
 		return 0;
 	return pthread__cond_wake_all(cond);
@@ -353,6 +357,10 @@ pthread_condattr_init(pthread_condattr_t
 int
 pthread_condattr_setclock(pthread_condattr_t *attr, clockid_t clck)
 {
+
+	pthread__error(EINVAL, "Invalid condition variable attribute",
+	    attr->ptca_magic == _PT_CONDATTR_MAGIC);
+
 	switch (clck) {
 	case CLOCK_MONOTONIC:
 	case CLOCK_REALTIME:
@@ -371,6 +379,10 @@ int
 pthread_condattr_getclock(const pthread_condattr_t *__restrict attr,
     clockid_t *__restrict clock_id)
 {
+
+	pthread__error(EINVAL, "Invalid condition variable attribute",
+	    attr->ptca_magic == _PT_CONDATTR_MAGIC);
+
 	if (attr == NULL || attr->ptca_private == NULL)
 		return EINVAL;
 	*clock_id = *(clockid_t *)attr->ptca_private;
@@ -396,6 +408,9 @@ pthread_condattr_getpshared(const pthrea
     int * __restrict pshared)
 {
 
+	pthread__error(EINVAL, "Invalid condition variable attribute",
+	    attr->ptca_magic == _PT_CONDATTR_MAGIC);
+
 	*pshared = PTHREAD_PROCESS_PRIVATE;
 	return 0;
 }
@@ -404,6 +419,9 @@ int
 pthread_condattr_setpshared(pthread_condattr_t *attr, int pshared)
 {
 
+	pthread__error(EINVAL, "Invalid condition variable attribute",
+	    attr->ptca_magic == _PT_CONDATTR_MAGIC);
+
 	switch(pshared) {
 	case PTHREAD_PROCESS_PRIVATE:
 		return 0;

Reply via email to