mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-30 18:40:46 +00:00
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: https://origsvn.digium.com/svn/asterisk/trunk@89637 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -1139,8 +1139,10 @@ long int ast_random(void)
|
|||||||
if (dev_urandom_fd >= 0) {
|
if (dev_urandom_fd >= 0) {
|
||||||
int read_res = read(dev_urandom_fd, &res, sizeof(res));
|
int read_res = read(dev_urandom_fd, &res, sizeof(res));
|
||||||
if (read_res > 0) {
|
if (read_res > 0) {
|
||||||
|
long int rm = RAND_MAX;
|
||||||
res = res < 0 ? ~res : res;
|
res = res < 0 ? ~res : res;
|
||||||
return res;
|
rm++;
|
||||||
|
return res % rm;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user