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
This commit is contained in:
Doug Thayer 2017-06-23 12:56:03 -04:00
parent 6ecbd1702f
commit 366ebfc80f
2 changed files with 25 additions and 16 deletions

View file

@ -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<time_t>(utcSeconds), &tm))
return 0;

View file

@ -5,6 +5,8 @@
#include "nsRFPService.h"
#include <time.h>
#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
}
}