Bug 1382840 - Making the nsRFPService::UpdatePref() to copy the string which been passed to PR_SetEnv(). r=Ehsan, a=jcristau
authorTim Huang <tihuang@mozilla.com>
Fri, 21 Jul 2017 11:49:21 +0800
changeset 412122 459b23d30228b91a54aa955cf65c907b3a798297
parent 412121 60f41b3decf8b73346d6641ebb0449ed7bfbab20
child 412123 2686c54f0fe8123f33b47789611c6a20cc4c5505
push id7556
push userryanvm@gmail.com
push dateThu, 27 Jul 2017 17:53:39 +0000
treeherdermozilla-beta@59a80d6ba08d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersEhsan, jcristau
bugs1382840
milestone55.0
Bug 1382840 - Making the nsRFPService::UpdatePref() to copy the string which been passed to PR_SetEnv(). r=Ehsan, a=jcristau 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
@@ -133,17 +133,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.