aboutsummaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authortilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2008-02-27 18:20:35 +0000
committertilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2008-02-27 18:20:35 +0000
commit8b6f404342d27abed3cfd5bf05bd0fa04aba020e (patch)
treeda196b24286b2f83c5ceddaa9e89fe1313a950ea /main
parentde520fcf454c633c7524861df97e85307488ced2 (diff)
Merged revisions 104704 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r104704 | tilghman | 2008-02-27 12:15:10 -0600 (Wed, 27 Feb 2008) | 2 lines Ensure the session ID can't be 0. ........ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@104705 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main')
-rw-r--r--main/manager.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/main/manager.c b/main/manager.c
index 7fb16a403..3eeecd5b6 100644
--- a/main/manager.c
+++ b/main/manager.c
@@ -3443,7 +3443,12 @@ static struct ast_str *generic_http_callback(enum output_format format,
ast_mutex_init(&s->__lock);
ast_mutex_lock(&s->__lock);
s->inuse = 1;
- s->managerid = (rand() ^ (unsigned long) s) | 1; /* make sure it is non-zero */
+ /*!\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);
s->last_ev = grab_last();
AST_LIST_LOCK(&sessions);
AST_LIST_INSERT_HEAD(&sessions, s, list);