Bug 1435721: Use NS_MakeRandomString for salting the profile directory. r=florian
authorDave Townsend <dtownsend@oxymoronical.com>
Fri, 29 Jun 2018 13:23:18 +0000
changeset 424429 bfff309c16437d516edbff04492c5d834d659eff
parent 424428 2f3ec97c623609ee9e6eaa2fb11de1efa5e73f47
child 424430 1afebbbd7b369e3286d47e78d9241ddda0a269a3
push id34207
push userccoroiu@mozilla.com
push dateFri, 29 Jun 2018 21:51:33 +0000
treeherdermozilla-central@b74ccfcd99d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersflorian
bugs1435721, 867769
milestone63.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 1435721: Use NS_MakeRandomString for salting the profile directory. r=florian This function is practically identical to the code used to salt the profile directory except it was fixed to not return matching strings when called in the same second by bug 867769. Differential Revision: https://phabricator.services.mozilla.com/D1865
toolkit/profile/nsToolkitProfileService.cpp
--- a/toolkit/profile/nsToolkitProfileService.cpp
+++ b/toolkit/profile/nsToolkitProfileService.cpp
@@ -688,34 +688,20 @@ NS_LockProfilePath(nsIFile* aPath, nsIFi
 
     nsresult rv = lock->Init(aPath, aTempPath, aUnlocker);
     if (NS_FAILED(rv)) return rv;
 
     lock.forget(aResult);
     return NS_OK;
 }
 
-static const char kTable[] =
-    { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
-      'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
-      '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' };
-
 static void SaltProfileName(nsACString& aName)
 {
-    double fpTime = double(PR_Now());
-
-    // use 1e-6, granularity of PR_Now() on the mac is seconds
-    srand((unsigned int)(fpTime * 1e-6 + 0.5));
-
     char salt[9];
-
-    int i;
-    for (i = 0; i < 8; ++i)
-        salt[i] = kTable[rand() % ArrayLength(kTable)];
-
+    NS_MakeRandomString(salt, 8);
     salt[8] = '.';
 
     aName.Insert(salt, 0, 9);
 }
 
 NS_IMETHODIMP
 nsToolkitProfileService::CreateProfile(nsIFile* aRootDir,
                                        const nsACString& aName,