Verified Commit 569b77d5 authored by Pier Angelo Vendrame's avatar Pier Angelo Vendrame 🎃 Committed by boklm
Browse files

fixup! TB 43107: Disable remoting by default

TB 44706: Fix a crash when creating new profiles.

Rework the patch to disable remoting at runtime to allow using some of
the service's functionalities, while still refusing to create any
remoting server/client.
parent 1a342a3a
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -53,7 +53,8 @@ nsStartupLock::~nsStartupLock() {

NS_IMPL_ISUPPORTS(nsRemoteService, nsIObserver, nsIRemoteService)

nsRemoteService::nsRemoteService() : mProgram("mozilla") {
nsRemoteService::nsRemoteService(bool aRemotingEnabled)
    : mRemotingEnabled(aRemotingEnabled), mProgram("mozilla") {
  ToLowerCase(mProgram);
}

@@ -194,6 +195,10 @@ nsresult nsRemoteService::SendCommandLine(const nsACString& aProfile,
    return NS_ERROR_FAILURE;
  }

  if (!mRemotingEnabled) {
    return NS_ERROR_NOT_AVAILABLE;
  }

  UniquePtr<nsRemoteClient> client;
#ifdef MOZ_WIDGET_GTK
#  if defined(MOZ_ENABLE_DBUS)
@@ -249,7 +254,7 @@ nsresult nsRemoteService::StartClient() {
}

void nsRemoteService::StartupServer() {
  if (mRemoteServer) {
  if (mRemoteServer || !mRemotingEnabled) {
    return;
  }

+2 −1
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ class nsRemoteService final : public nsIObserver, public nsIRemoteService {
  NS_DECL_NSIOBSERVER
  NS_DECL_NSIREMOTESERVICE

  nsRemoteService();
  nsRemoteService(bool aRemotingEnabled);
  void SetProgram(const char* aProgram);
  void SetProfile(nsACString& aProfile);
#ifdef MOZ_WIDGET_GTK
@@ -91,6 +91,7 @@ class nsRemoteService final : public nsIObserver, public nsIRemoteService {
  nsresult SendCommandLine(const nsACString& aProfile, size_t aArgc,
                           const char** aArgv, bool aRaise);

  bool mRemotingEnabled;
  mozilla::UniquePtr<nsRemoteServer> mRemoteServer;
  nsCString mProgram;
  nsCString mProfile;
+8 −10
Original line number Diff line number Diff line
@@ -315,7 +315,7 @@ static nsIProfileLock* gProfileLock;
constinit static RefPtr<nsRemoteService> gRemoteService;
constinit static RefPtr<nsStartupLock> gStartupLock;
// tor-browser#43107: Disable remoting by default.
bool gDisableRemoting = true;
bool gEnableRemoting = false;
#endif

int gRestartArgc;
@@ -2096,8 +2096,8 @@ nsresult ScopedXPCOMStartup::SetWindowCreator(nsINativeAppSupport* native) {
/* static */ already_AddRefed<nsIRemoteService> GetRemoteService() {
  AssertIsOnMainThread();

  if (!gRemoteService && !gDisableRemoting) {
    gRemoteService = new nsRemoteService();
  if (!gRemoteService) {
    gRemoteService = new nsRemoteService(gEnableRemoting);
  }
  nsCOMPtr<nsIRemoteService> remoteService = gRemoteService.get();
  return remoteService.forget();
@@ -4496,7 +4496,7 @@ int XREMain::XRE_mainInit(bool* aExitFlag) {
  // The user can still enable remoting if they want to, by adding the
  // allow-remote parameter to the command line.
  if (CheckArg("allow-remote") == ARG_FOUND) {
    gDisableRemoting = false;
    gEnableRemoting = true;
  }
#else
  // These arguments do nothing in platforms with no remoting support but we
@@ -4891,7 +4891,7 @@ int XREMain::XRE_mainStartup(bool* aExitFlag) {

#ifdef MOZ_HAS_REMOTE
  if (gfxPlatform::IsHeadless()) {
    gDisableRemoting = true;
    gEnableRemoting = false;
  }
#endif

@@ -5013,10 +5013,8 @@ int XREMain::XRE_mainStartup(bool* aExitFlag) {
  }
#endif
#if defined(MOZ_HAS_REMOTE)
  if (!gDisableRemoting) {
  // handle --remote now that xpcom is fired up
    gRemoteService = new nsRemoteService();
  }
  gRemoteService = new nsRemoteService(gEnableRemoting);
  if (gRemoteService) {
    gRemoteService->SetProgram(gAppData->remotingName);
    gStartupLock = gRemoteService->LockStartup();
@@ -5101,7 +5099,7 @@ int XREMain::XRE_mainStartup(bool* aExitFlag) {
    if (NS_SUCCEEDED(rv)) {
      gRemoteService->SetProfile(profilePath);

      if (!gDisableRemoting) {
      if (gEnableRemoting) {
        // Try to remote the entire command line. If this fails, start up
        // normally.
#  ifdef MOZ_WIDGET_GTK