aboutsummaryrefslogtreecommitdiffstats
path: root/main/utils.c
diff options
context:
space:
mode:
authorfile <file@f38db490-d61c-443f-a65b-d21fe96a405b>2007-11-27 17:01:19 +0000
committerfile <file@f38db490-d61c-443f-a65b-d21fe96a405b>2007-11-27 17:01:19 +0000
commit942e20012a449ab62185f69049601f8a0a9b4392 (patch)
tree5d5af517c07fce30224248a8476abb28a9a6e918 /main/utils.c
parentba864b3835636bdb43033e12d25ce6539878d446 (diff)
Ensure the value returned from ast_random is between 0 and RAND_MAX on 64-bit platforms.
(closes issue #11348) Reported by: sperreault git-svn-id: http://svn.digium.com/svn/asterisk/trunk@89637 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/utils.c')
-rw-r--r--main/utils.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/main/utils.c b/main/utils.c
index d40a74939..5d6466175 100644
--- a/main/utils.c
+++ b/main/utils.c
@@ -1139,8 +1139,10 @@ long int ast_random(void)
if (dev_urandom_fd >= 0) {
int read_res = read(dev_urandom_fd, &res, sizeof(res));
if (read_res > 0) {
+ long int rm = RAND_MAX;
res = res < 0 ? ~res : res;
- return res;
+ rm++;
+ return res % rm;
}
}
#endif