Bug 1015547 - Fill |struct nsID| via arc4random_buf if available on Android and BSDs. r=vlad, r=glandium

This commit is contained in:
Jan Beich 2014-05-29 23:09:00 -04:00
parent 76debdf99c
commit d012fe1bfa
2 changed files with 5 additions and 1 deletions

View File

@ -2946,7 +2946,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 arc4random)
AC_CHECK_FUNCS(stat64 lstat64 truncate64 statvfs64 statvfs statfs64 statfs getpagesize localtime_r arc4random arc4random_buf)
dnl check for clock_gettime(), the CLOCK_MONOTONIC clock
AC_CACHE_CHECK(for clock_gettime(CLOCK_MONOTONIC),

View File

@ -126,6 +126,9 @@ nsUUIDGenerator::GenerateUUIDInPlace(nsID* aId)
setstate(mState);
#endif
#ifdef HAVE_ARC4RANDOM_BUF
arc4random_buf(aId, sizeof(nsID));
#else /* HAVE_ARC4RANDOM_BUF */
size_t bytesLeft = sizeof(nsID);
while (bytesLeft > 0) {
#ifdef HAVE_ARC4RANDOM
@ -150,6 +153,7 @@ nsUUIDGenerator::GenerateUUIDInPlace(nsID* aId)
bytesLeft -= toWrite;
}
#endif /* HAVE_ARC4RANDOM_BUF */
/* Put in the version */
aId->m2 &= 0x0fff;