Bug 1382840 - Making the nsRFPService::UpdatePref() to copy the string which been passed to PR_SetEnv(). r=Ehsan
authorTim Huang <tihuang@mozilla.com>
Fri, 21 Jul 2017 11:49:21 +0800
changeset 419272 80b3b7fa1e23f3c504a9013a219218238a20ce63
parent 419271 7e21499a9eb443a7492c722930e7b0c21f8ce433
child 419273 17d7de773b6d3aecd88fdd7882b7d236b4f62e37
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersEhsan
bugs1382840
milestone56.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 1382840 - Making the nsRFPService::UpdatePref() to copy the string which been passed to PR_SetEnv(). r=Ehsan The PR_SetEnv() needs the passing string been intentionally leaked. However, nsRFPService::UpdatePref() uses PR_SetEnv() without leaking the input string. This patch is going to fix this by using ToNewCString(). MozReview-Commit-ID: 97QQUk2sjM9
toolkit/components/resistfingerprinting/nsRFPService.cpp
--- a/toolkit/components/resistfingerprinting/nsRFPService.cpp
+++ b/toolkit/components/resistfingerprinting/nsRFPService.cpp
@@ -143,17 +143,29 @@ nsRFPService::UpdatePref()
     PR_SetEnv("TZ=UTC");
     JS::SetTimeResolutionUsec(kResolutionUSec);
   } else if (sInitialized) {
     JS::SetTimeResolutionUsec(0);
     // We will not touch the TZ value if 'privacy.resistFingerprinting' is false during
     // the time of initialization.
     if (!mInitialTZValue.IsEmpty()) {
       nsAutoCString tzValue = NS_LITERAL_CSTRING("TZ=") + mInitialTZValue;
-      PR_SetEnv(tzValue.get());
+      static char* tz = nullptr;
+
+      // If the tz has been set before, we free it first since it will be allocated
+      // a new value later.
+      if (tz) {
+        free(tz);
+      }
+      // PR_SetEnv() needs the input string been leaked intentionally, so
+      // we copy it here.
+      tz = ToNewCString(tzValue);
+      if (tz) {
+        PR_SetEnv(tz);
+      }
     } else {
 #if defined(XP_LINUX) || defined (XP_MACOSX)
       // For POSIX like system, we reset the TZ to the /etc/localtime, which is the
       // system timezone.
       PR_SetEnv("TZ=:/etc/localtime");
 #else
       // For Windows, we reset the TZ to an empty string. This will make Windows to use
       // its system timezone.