[asterisk-commits] file: trunk r89576 - /trunk/main/utils.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Nov 26 09:28:14 CST 2007


Author: file
Date: Mon Nov 26 09:28:13 2007
New Revision: 89576

URL: http://svn.digium.com/view/asterisk?view=rev&rev=89576
Log:
Make the behavior of using /dev/urandom for random numbers the same as random().
(closes issue #11348)
Reported by: sperreault
Patches:
      ast_random2.diff uploaded by sperreault (license 252)

Modified:
    trunk/main/utils.c

Modified: trunk/main/utils.c
URL: http://svn.digium.com/view/asterisk/trunk/main/utils.c?view=diff&rev=89576&r1=89575&r2=89576
==============================================================================
--- trunk/main/utils.c (original)
+++ trunk/main/utils.c Mon Nov 26 09:28:13 2007
@@ -1138,8 +1138,10 @@
 #ifdef HAVE_DEV_URANDOM
 	if (dev_urandom_fd >= 0) {
 		int read_res = read(dev_urandom_fd, &res, sizeof(res));
-		if (read_res > 0)
-			return res < 0 ? ~res : res;
+		if (read_res > 0) {
+			res = res < 0 ? ~res : res;
+			return res % ((long)RAND_MAX + 1);
+		}
 	}
 #endif
 #ifdef linux




More information about the asterisk-commits mailing list