[asterisk-commits] tilghman: branch 1.4 r104704 - /branches/1.4/main/manager.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Feb 27 12:15:10 CST 2008


Author: tilghman
Date: Wed Feb 27 12:15:10 2008
New Revision: 104704

URL: http://svn.digium.com/view/asterisk?view=rev&rev=104704
Log:
Ensure the session ID can't be 0.

Modified:
    branches/1.4/main/manager.c

Modified: branches/1.4/main/manager.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/main/manager.c?view=diff&rev=104704&r1=104703&r2=104704
==============================================================================
--- branches/1.4/main/manager.c (original)
+++ branches/1.4/main/manager.c Wed Feb 27 12:15:10 2008
@@ -2660,7 +2660,12 @@
 		ast_mutex_init(&s->__lock);
 		ast_mutex_lock(&s->__lock);
 		s->inuse = 1;
-		s->managerid = rand() ^ (unsigned long) s;
+		/*!\note There is approximately a 1 in 1.8E19 chance that the following
+		 * calculation will produce 0, which is an invalid ID, but due to the
+		 * properties of the rand() function (and the constantcy of s), that
+		 * won't happen twice in a row.
+		 */
+		while ((s->managerid = rand() ^ (unsigned long) s) == 0);
 		AST_LIST_LOCK(&sessions);
 		AST_LIST_INSERT_HEAD(&sessions, s, list);
 		/* Hook into the last spot in the event queue */




More information about the asterisk-commits mailing list