diff options
author | Mark Michelson <mmichelson@digium.com> | 2007-11-21 18:19:22 +0000 |
---|---|---|
committer | Mark Michelson <mmichelson@digium.com> | 2007-11-21 18:19:22 +0000 |
commit | 3851bc9789bcdaf4259b1159cb1067559f89c47f (patch) | |
tree | f1637260251b287378f4adde2a63222c2cd44b38 /main/utils.c | |
parent | 6d8d66e9e7d795a5668ddcb8539a15b4458068d2 (diff) |
There existed about a 1 in 4 billion chance that reading from /dev/urandom
would return LONG_MIN (1 in 9 quintillion if using 64-bit longs). Since there
is no positive equivalent of LONG_MIN, the result of labs() in this case is
unpredictable. This fixes that situation.
(closes issue #11336, reported and patched by sperreault)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89487 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/utils.c')
-rw-r--r-- | main/utils.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/main/utils.c b/main/utils.c index 8b3448f02..83ab65ac1 100644 --- a/main/utils.c +++ b/main/utils.c @@ -1140,7 +1140,7 @@ long int ast_random(void) if (dev_urandom_fd >= 0) { int read_res = read(dev_urandom_fd, &res, sizeof(res)); if (read_res > 0) - return labs(res); + return res < 0 ? ~res : res; } #endif #ifdef linux |