From 366ebfc80f8ce47b167f7dbaf73f98ea30a30a84 Mon Sep 17 00:00:00 2001 From: Doug Thayer Date: Fri, 23 Jun 2017 12:56:03 -0400 Subject: [PATCH] Bug 1361500 - Don't call _tzset on startup r=arthuredelstein,Ehsan The reason we call _tzset inside DateTime.cpp is to allow the privacy.resistFingerprinting pref to mask our timezone by setting the TZ environment variable. Without _tzset, the changes to the environment variable won't actually change anything. However, if a process is started with the TZ environment variable set to something (like "UTC"), then those changes will be active in that process. Since we're only masking timezone to JS running in the content process, and since those content processes will be started by the parent process which has already set its TZ to UTC, and will copy that variable to its children, we only need to call _tzset() when the pref changes, and only in the content process, provided we are on e10s. MozReview-Commit-ID: CPU99BGDUPj --HG-- extra : rebase_source : 4cdf6b5e2aebeff34decd11efa62783f2364dd3a --- js/src/vm/DateTime.cpp | 14 ---------- .../resistfingerprinting/nsRFPService.cpp | 27 +++++++++++++++++-- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/js/src/vm/DateTime.cpp b/js/src/vm/DateTime.cpp index 8d4b6e3f8146..3225165e5eb4 100644 --- a/js/src/vm/DateTime.cpp +++ b/js/src/vm/DateTime.cpp @@ -72,13 +72,6 @@ UTCToLocalStandardOffsetSeconds() using js::SecondsPerHour; using js::SecondsPerMinute; -#if defined(XP_WIN) - // Windows doesn't follow POSIX: updates to the TZ environment variable are - // not reflected immediately on that platform as they are on other systems - // without this call. - _tzset(); -#endif - // Get the current time. time_t currentMaybeWithDST = time(nullptr); if (currentMaybeWithDST == time_t(-1)) @@ -180,13 +173,6 @@ js::DateTimeInfo::computeDSTOffsetMilliseconds(int64_t utcSeconds) MOZ_ASSERT(utcSeconds >= 0); MOZ_ASSERT(utcSeconds <= MaxUnixTimeT); -#if defined(XP_WIN) - // Windows does not follow POSIX. Updates to the TZ environment variable - // are not reflected immediately on that platform as they are on UNIX - // systems without this call. - _tzset(); -#endif - struct tm tm; if (!ComputeLocalTime(static_cast(utcSeconds), &tm)) return 0; diff --git a/toolkit/components/resistfingerprinting/nsRFPService.cpp b/toolkit/components/resistfingerprinting/nsRFPService.cpp index 83fda0246b88..af096c960f39 100644 --- a/toolkit/components/resistfingerprinting/nsRFPService.cpp +++ b/toolkit/components/resistfingerprinting/nsRFPService.cpp @@ -5,6 +5,8 @@ #include "nsRFPService.h" +#include + #include "mozilla/ClearOnShutdown.h" #include "mozilla/Preferences.h" #include "mozilla/Services.h" @@ -13,6 +15,7 @@ #include "nsCOMPtr.h" #include "nsServiceManagerUtils.h" #include "nsString.h" +#include "nsXULAppAPI.h" #include "nsIObserverService.h" #include "nsIPrefBranch.h" @@ -120,6 +123,19 @@ nsRFPService::Init() // Call UpdatePref() here to cache the value of 'privacy.resistFingerprinting' // and set the timezone. UpdatePref(); + +#if defined(XP_WIN) + // If we're e10s, then we don't need to run this, since the child process will + // simply inherit the environment variable from the parent process, in which + // case it's unnecessary to call _tzset(). + if (XRE_IsParentProcess() && !XRE_IsE10sParentProcess()) { + // Windows does not follow POSIX. Updates to the TZ environment variable + // are not reflected immediately on that platform as they are on UNIX + // systems without this call. + _tzset(); + } +#endif + return rv; } @@ -152,8 +168,6 @@ nsRFPService::UpdatePref() } } - // We don't have to call _tzset() here for Windows since the following - // function nsJSUtils::ResetTimeZone() will call it for us. nsJSUtils::ResetTimeZone(); } @@ -184,6 +198,15 @@ nsRFPService::Observe(nsISupports* aObject, const char* aTopic, if (pref.EqualsLiteral(RESIST_FINGERPRINTING_PREF)) { UpdatePref(); + +#if defined(XP_WIN) + if (!XRE_IsE10sParentProcess()) { + // Windows does not follow POSIX. Updates to the TZ environment variable + // are not reflected immediately on that platform as they are on UNIX + // systems without this call. + _tzset(); + } +#endif } }