components/open-fabrics/libibmad/patches/002-libibmad-diskmon_trid.patch
author boris.chiu@oracle.com
Mon, 19 Sep 2016 15:30:46 -0700
branchs11u3-sru
changeset 6927 af9bb41e858d
permissions -rw-r--r--
22086045 libibmad used [s]random(3c) functions unsafely

#This patch was developed both in-house and from outside. We plan to submit it
#upstream, but do not yet have a target date for doing so
#
# HG changeset patch
# Parent  b0c54b9f271e37d7b605138bcdd0c26844892c3d
22086045 libibmad used [s]random(3c) functions unsafely

diff -r b0c54b9f271e src/mad.c
--- a/src/mad.c	Mon Aug 15 14:55:29 2016 -0700
+++ b/src/mad.c	Mon Aug 15 15:01:53 2016 -0700
@@ -41,6 +41,9 @@
 #include <stdlib.h>
 #include <string.h>
 #include <time.h>
+#if defined(__SVR4) && defined(__sun)
+#include <pthread.h>
+#endif
 #include <errno.h>
 
 #include <infiniband/umad.h>
@@ -48,6 +51,10 @@
 
 #include "mad_internal.h"
 
+#if defined(__SVR4) && defined(__sun)
+static pthread_mutex_t trid_mutex = PTHREAD_MUTEX_INITIALIZER;
+#endif
+
 #undef DEBUG
 #define DEBUG	if (ibdebug)	IBWARN
 
@@ -63,11 +70,17 @@
 	static uint64_t trid;
 	uint64_t next;
 
+#if defined(__SVR4) && defined(__sun)
+	(void) pthread_mutex_lock(&trid_mutex);
+#endif
 	if (!trid) {
 		srandom((int)time(0) * getpid());
 		trid = random();
 	}
 	next = ++trid;
+#if defined(__SVR4) && defined(__sun)
+	(void) pthread_mutex_unlock(&trid_mutex);
+#endif
 	next = GET_IB_USERLAND_TID(next);
 	return next;
 }