From 40ff1f7b41e496dc83cdac7db94990feba93bb14 Mon Sep 17 00:00:00 2001 From: mmichelson Date: Wed, 21 Nov 2007 18:19:22 +0000 Subject: 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: http://svn.digium.com/svn/asterisk/trunk@89487 f38db490-d61c-443f-a65b-d21fe96a405b --- main/utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'main/utils.c') 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 -- cgit v1.2.3