cpw.darkrain42.xmpp.bosh: 06a295e0: A better random number for the rid in th...

paul at darkrain42.org paul at darkrain42.org
Sat Apr 4 19:15:40 EDT 2009


-----------------------------------------------------------------
Revision: 06a295e020eccbf9caabb99c59a341b531098f43
Ancestor: c5fd55781adf871dcfade5b1d401181700ad0927
Author: paul at darkrain42.org
Date: 2009-04-04T21:49:34
Branch: im.pidgin.cpw.darkrain42.xmpp.bosh
URL: http://d.pidgin.im/viewmtn/revision/info/06a295e020eccbf9caabb99c59a341b531098f43

Modified files:
        libpurple/protocols/jabber/bosh.c

ChangeLog: 

A better random number for the rid in the range [0, 2**52).

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/bosh.c	55a20f44165d05093e77f1647da6b95c3eb5d1e6
+++ libpurple/protocols/jabber/bosh.c	63f3731f3cb0d172094d200e4053b3c6edc9ab8c
@@ -176,9 +176,16 @@ jabber_bosh_connection_init(JabberStream
 	g_free(passwd);
 
 	conn->js = js;
-	/* FIXME: This doesn't seem very random */
-	conn->rid = rand() % 100000 + 1728679472;
 
+	/*
+	 * Random 64-bit integer masked off by 2^52 - 1.
+	 *
+	 * This should produce a random integer in the range [0, 2^52). It's
+	 * unlikely we'll send enough packets in one session to overflow the rid.
+	 */
+	conn->rid = ((guint64)g_random_int() << 32) | g_random_int();
+	conn->rid &= 0xFFFFFFFFFFFFF;
+
 	conn->pending = purple_circ_buffer_new(0 /* default grow size */);
 
 	conn->ready = FALSE;


More information about the Commits mailing list