From ec63fcb314c7f83d9504297c69483f944d5ee29b Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 6 Jun 2017 17:38:06 -0700 Subject: [PATCH] QRandomGenerator: use arc4random as fallback on BSDs (including Darwin) This function works even in chroots where /dev is not available. Since it's part of the OS, it may have better ways of gathering entropy even when we don't. Change-Id: Ia3e896da908f42939148fffd14c5afedc8569dbc Reviewed-by: Lars Knoll --- src/corelib/global/qrandom.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/corelib/global/qrandom.cpp b/src/corelib/global/qrandom.cpp index 954e879887..5c2548184b 100644 --- a/src/corelib/global/qrandom.cpp +++ b/src/corelib/global/qrandom.cpp @@ -200,6 +200,13 @@ static void fallback_fill(quint32 *ptr, qssize_t left) Q_DECL_NOTHROW return value; }); } +#elif defined(Q_OS_BSD4) +static void fallback_update_seed(unsigned) {} +static void fallback_fill(quint32 *ptr, qssize_t left) Q_DECL_NOTHROW +{ + // BSDs have arc4random(4) and these work even in chroot(2) + arc4random_buf(ptr, left * sizeof(*ptr)); +} #elif QT_HAS_INCLUDE() static QBasicAtomicInteger seed = Q_BASIC_ATOMIC_INITIALIZER(0U); static void fallback_update_seed(unsigned value)