summaryrefslogtreecommitdiff
path: root/random.c
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-09-04 01:42:37 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-09-04 01:42:37 +0000
commitb120f5e38d9c9817a18723d8002665e6dd29f7a6 (patch)
tree5656a7add2b63228a973ab4d932b4614b7d03f61 /random.c
parent183ac396d4275f3830a835ba8c3feb3b5ef8f964 (diff)
avoid fork-unsafe arc4random implementations
Some old implementaions of arc4random_buf(3) were ARC4 based, or unsafe when forked, or both. Resort to /dev/urandom for those known problematic cases. Fix [Bug #15039] Patch from Thomas Hurst <tom@hur.st> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64625 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'random.c')
-rw-r--r--random.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/random.c b/random.c
index 4add8868fb..9579cfce21 100644
--- a/random.c
+++ b/random.c
@@ -494,8 +494,14 @@ fill_random_bytes_syscall(void *seed, size_t size, int unused)
static int
fill_random_bytes_syscall(void *buf, size_t size, int unused)
{
+#if (defined(__OpenBSD__) && OpenBSD >= 201411) || \
+ (defined(__NetBSD__) && __NetBSD_Version__ >= 700000000) || \
+ (defined(__FreeBSD__) && __FreeBSD_version >= 1200079)
arc4random_buf(buf, size);
return 0;
+#else
+ return -1;
+#endif
}
#elif defined(_WIN32)
static void