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
--- 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.