From ab15f65fe5d6d50e705c1064a6a5c1a0c2a8e045 Mon Sep 17 00:00:00 2001 From: Matthieu Herrb Date: Tue, 28 Feb 2017 19:18:43 +0100 Subject: Use arc4random_buf(3) if available to generate cookies. Reviewed-by: Adam Jackson Signed-off-by: Matthieu Herrb (cherry picked from commit 957e8db38f27932d353e86e9aa69cf16778b18f1) --- os/auth.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'os/auth.c') diff --git a/os/auth.c b/os/auth.c index 7da6fc6ed..81164a2f5 100644 --- a/os/auth.c +++ b/os/auth.c @@ -45,6 +45,9 @@ from The Open Group. #ifdef WIN32 #include #endif +#ifdef HAVE_LIBBSD +#include /* for arc4random_buf() */ +#endif struct protocol { unsigned short name_length; @@ -303,11 +306,15 @@ GenerateAuthorization(unsigned name_length, void GenerateRandomData(int len, char *buf) { +#ifdef HAVE_ARC4RANDOMBUF + arc4random_buf(buf, len); +#else int fd; fd = open("/dev/urandom", O_RDONLY); read(fd, buf, len); close(fd); +#endif } #endif /* XCSECURITY */ -- cgit v1.2.3