Bug 1015547 - Fill |struct nsID| via arc4random_buf if available on Android and BSDs. r=vlad, r=glandium
☠☠ backed out by 67d59294aef1 ☠ ☠
authorJan Beich <jbeich@tormail.org>
Thu, 29 May 2014 23:09:00 -0400
changeset 206261 7b6b2d8dd79b7d050a20471b63fada1cb74b3bff
parent 206260 16e5c41a089357fee6d2417d889d8b7b90b99694
child 206262 646dcacbd009acfdd03a1df31854b5da4478c04f
push id494
push userraliiev@mozilla.com
push dateMon, 25 Aug 2014 18:42:16 +0000
treeherdermozilla-release@a3cc3e46b571 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvlad, glandium
bugs1015547
milestone32.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1015547 - Fill |struct nsID| via arc4random_buf if available on Android and BSDs. r=vlad, r=glandium
configure.in
xpcom/base/nsUUIDGenerator.cpp
--- a/configure.in
+++ b/configure.in
@@ -2941,17 +2941,17 @@ then
     AC_SUBST(MOZ_USE_PTHREADS)
 fi
 
 
 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),
                ac_cv_clock_monotonic,
                [for libs in "" -lrt; do
                     _SAVE_LIBS="$LIBS"
                     LIBS="$LIBS $libs"
                     AC_TRY_LINK([#include <time.h>],
--- a/xpcom/base/nsUUIDGenerator.cpp
+++ b/xpcom/base/nsUUIDGenerator.cpp
@@ -121,16 +121,19 @@ nsUUIDGenerator::GenerateUUIDInPlace(nsI
   /* XXX we should be saving the return of setstate here and switching
    * back to it; instead, we use the value returned when we called
    * initstate, since older glibc's have broken setstate() return values
    */
 #ifndef HAVE_ARC4RANDOM
   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
     long rval = arc4random();
     const size_t mRBytes = 4;
 #else
     long rval = random();
 #endif
@@ -145,16 +148,17 @@ nsUUIDGenerator::GenerateUUIDInPlace(nsI
     uint8_t* dst = ((uint8_t*)aId) + (sizeof(nsID) - bytesLeft);
     size_t toWrite = (bytesLeft < mRBytes ? bytesLeft : mRBytes);
     for (size_t i = 0; i < toWrite; i++) {
       dst[i] = src[i];
     }
 
     bytesLeft -= toWrite;
   }
+#endif /* HAVE_ARC4RANDOM_BUF */
 
   /* Put in the version */
   aId->m2 &= 0x0fff;
   aId->m2 |= 0x4000;
 
   /* Put in the variant */
   aId->m3[0] &= 0x3f;
   aId->m3[0] |= 0x80;