Bug 1015547 - Prefer arc4random to generate UUIDs on BSDs. r=vlad, r=glandium

This commit is contained in:
Jan Beich 2014-06-02 18:41:00 -04:00
Родитель f2dcba3d01
Коммит ddc9fe103d
3 изменённых файлов: 7 добавлений и 7 удалений

Просмотреть файл

@ -2928,7 +2928,7 @@ dnl Checks for library functions.
dnl ========================================================
AC_PROG_GCC_TRADITIONAL
AC_FUNC_MEMCMP
AC_CHECK_FUNCS(stat64 lstat64 truncate64 statvfs64 statvfs statfs64 statfs getpagesize localtime_r)
AC_CHECK_FUNCS(stat64 lstat64 truncate64 statvfs64 statvfs statfs64 statfs getpagesize localtime_r arc4random)
dnl check for clock_gettime(), the CLOCK_MONOTONIC clock
AC_CACHE_CHECK(for clock_gettime(CLOCK_MONOTONIC),

Просмотреть файл

@ -35,7 +35,7 @@ nsUUIDGenerator::Init()
// We're a service, so we're guaranteed that Init() is not going
// to be reentered while we're inside Init().
#if !defined(XP_WIN) && !defined(XP_MACOSX) && !defined(ANDROID)
#if !defined(XP_WIN) && !defined(XP_MACOSX) && !defined(HAVE_ARC4RANDOM)
/* initialize random number generator using NSPR random noise */
unsigned int seed;
@ -72,7 +72,7 @@ nsUUIDGenerator::Init()
}
#endif
#endif /* non XP_WIN and non XP_MACOSX */
#endif /* non XP_WIN and non XP_MACOSX and non ARC4RANDOM */
return NS_OK;
}
@ -122,13 +122,13 @@ nsUUIDGenerator::GenerateUUIDInPlace(nsID* aId)
* back to it; instead, we use the value returned when we called
* initstate, since older glibc's have broken setstate() return values
*/
#ifndef ANDROID
#ifndef HAVE_ARC4RANDOM
setstate(mState);
#endif
size_t bytesLeft = sizeof(nsID);
while (bytesLeft > 0) {
#ifdef ANDROID
#ifdef HAVE_ARC4RANDOM
long rval = arc4random();
const size_t mRBytes = 4;
#else
@ -159,7 +159,7 @@ nsUUIDGenerator::GenerateUUIDInPlace(nsID* aId)
aId->m3[0] &= 0x3f;
aId->m3[0] |= 0x80;
#ifndef ANDROID
#ifndef HAVE_ARC4RANDOM
/* Restore the previous RNG state */
setstate(mSavedState);
#endif

Просмотреть файл

@ -29,7 +29,7 @@ private:
protected:
mozilla::Mutex mLock;
#if !defined(XP_WIN) && !defined(XP_MACOSX) && !defined(ANDROID)
#if !defined(XP_WIN) && !defined(XP_MACOSX) && !defined(HAVE_ARC4RANDOM)
char mState[128];
char* mSavedState;
uint8_t mRBytes;