Bug 1539208 - P2 - Use RandomNum while failing to get a random number from RandomGenerator; r=baku
authorTom Tung <shes050117@gmail.com>
Fri, 29 Mar 2019 09:04:10 +0000
changeset 466731 7b17d77256be8a810d75865b422a49b4adca7a90
parent 466730 cec67adbdbb6d5b2948a68e4f6fb13612f949368
child 466732 800d46efef526243036570465ab99000f61117d5
push id35780
push useropoprus@mozilla.com
push dateFri, 29 Mar 2019 21:53:01 +0000
treeherdermozilla-central@414f37afbe07 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1539208
milestone68.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 1539208 - P2 - Use RandomNum while failing to get a random number from RandomGenerator; r=baku Differential Revision: https://phabricator.services.mozilla.com/D25104
dom/fetch/InternalResponse.cpp
--- a/dom/fetch/InternalResponse.cpp
+++ b/dom/fetch/InternalResponse.cpp
@@ -6,16 +6,17 @@
 
 #include "InternalResponse.h"
 
 #include "mozilla/Assertions.h"
 #include "mozilla/dom/InternalHeaders.h"
 #include "mozilla/dom/cache/CacheTypes.h"
 #include "mozilla/ipc/PBackgroundSharedTypes.h"
 #include "mozilla/ipc/IPCStreamUtils.h"
+#include "mozilla/RandomNum.h"
 #include "nsIRandomGenerator.h"
 #include "nsIURI.h"
 #include "nsStreamUtils.h"
 
 namespace mozilla {
 namespace dom {
 
 namespace {
@@ -117,24 +118,34 @@ nsresult InternalResponse::GeneratePaddi
   MOZ_DIAGNOSTIC_ASSERT(mPaddingSize == UNKNOWN_PADDING_SIZE);
 
   // Utilize random generator to generator a random number
   nsresult rv;
   uint32_t randomNumber = 0;
   nsCOMPtr<nsIRandomGenerator> randomGenerator =
       do_GetService("@mozilla.org/security/random-generator;1", &rv);
   if (NS_WARN_IF(NS_FAILED(rv))) {
+    Maybe<uint64_t> maybeRandomNum = RandomUint64();
+    if (maybeRandomNum.isSome()) {
+      mPaddingInfo.emplace(uint32_t(maybeRandomNum.value() % kMaxRandomNumber));
+      return NS_OK;
+    }
     return rv;
   }
 
   MOZ_DIAGNOSTIC_ASSERT(randomGenerator);
 
   uint8_t* buffer;
   rv = randomGenerator->GenerateRandomBytes(sizeof(randomNumber), &buffer);
   if (NS_WARN_IF(NS_FAILED(rv))) {
+    Maybe<uint64_t> maybeRandomNum = RandomUint64();
+    if (maybeRandomNum.isSome()) {
+      mPaddingInfo.emplace(uint32_t(maybeRandomNum.value() % kMaxRandomNumber));
+      return NS_OK;
+    }
     return rv;
   }
 
   memcpy(&randomNumber, buffer, sizeof(randomNumber));
   free(buffer);
 
   mPaddingInfo.emplace(randomNumber % kMaxRandomNumber);