[asterisk-commits] mmichelson: branch mmichelson/uuid r376832 - /team/mmichelson/uuid/main/uuid.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Nov 29 12:19:39 CST 2012


Author: mmichelson
Date: Thu Nov 29 12:19:35 2012
New Revision: 376832

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=376832
Log:
Take precautions in the event of /dev/urandom being non-existent.

We place locks around the UUID generation if there is no /dev/urandom
present. Also, we output a warning on startup.


Modified:
    team/mmichelson/uuid/main/uuid.c

Modified: team/mmichelson/uuid/main/uuid.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/uuid/main/uuid.c?view=diff&rev=376832&r1=376831&r2=376832
==============================================================================
--- team/mmichelson/uuid/main/uuid.c (original)
+++ team/mmichelson/uuid/main/uuid.c Thu Nov 29 12:19:35 2012
@@ -27,6 +27,10 @@
 #include "asterisk/utils.h"
 #include "asterisk/strings.h"
 #include "asterisk/logger.h"
+
+#ifndef HAVE_DEV_URANDOM
+AST_MUTEX_STATIC(uuid_lock);
+#endif
 
 struct ast_uuid {
 	uuid_t uu;
@@ -96,7 +100,18 @@
 	 * Given these drawbacks, we stick to only using random UUIDs. The chance of /dev/random
 	 * or /dev/urandom not existing on systems in this age is next to none.
 	 */
+	
+	/* XXX Currently, we only protect this call if the user has no /dev/urandon on their system.
+	 * If it turns out that there are issues with UUID generation despite the presence of
+	 * /dev/urandom, then we may need to make the locking/unlocking unconditional.
+	 */
+#ifndef HAVE_DEV_URANDOM
+	ast_mutex_lock(&uuid_lock);
+#endif
 	uuid_generate_random(uuid->uu);
+#ifndef HAVE_DEV_URANDOM
+	ast_mutex_unlock(&uuid_lock);
+#endif
 	return uuid;
 }
 
@@ -168,6 +183,17 @@
 	 * Think of this along the same lines as initializing a singleton.
 	 */
 	uuid_t uu;
+#ifndef HAVE_DEV_URANDOM
+	ast_log(LOG_WARNING, "It appears your system does not have /dev/urandom on it. This\n"
+			"means that UUID generation will use a pseudorandom number generator. This\n"
+			"has two implications:\n"
+			"    1. Since the thread-safety of your system's random number generator cannot\n"
+			"       be guaranteed, we have to synchronize UUID generation. This may result\n"
+			"       in decreased performance.\n"
+			"    2. Random number generation is not guaranteed to be as random, meaning there is\n"
+			"       a very remote chance you may see duplicate UUIDs.\n"
+			"It is highly recommended that you set up your system to have /dev/urandom\n");
+#endif
 	uuid_generate_random(uu);
 
 	ast_debug(1, "UUID system initiated\n");




More information about the asterisk-commits mailing list