]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Ensure the session ID can't be 0.
authorTilghman Lesher <tilghman@meg.abyt.es>
Wed, 27 Feb 2008 18:15:10 +0000 (18:15 +0000)
committerTilghman Lesher <tilghman@meg.abyt.es>
Wed, 27 Feb 2008 18:15:10 +0000 (18:15 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@104704 65c4cc65-6c06-0410-ace0-fbb531ad65f3

main/manager.c

index 3edbc3e2248f579365292fb1ea937aefe33e053a..b78ecf5e3539b1a2ab620a72175a67f21f4b4def 100644 (file)
@@ -2660,7 +2660,12 @@ static char *generic_http_callback(int format, struct sockaddr_in *requestor, co
                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 */