Skip to content

Commit

Permalink
Bug 1738984 - Prevent NSS initialization and channel creation during …
Browse files Browse the repository at this point in the history
…shutdown r=keeler

Differential Revision: https://phabricator.services.mozilla.com/D133065
  • Loading branch information
valenting committed Dec 7, 2021
1 parent 76d1b12 commit ea4d1a5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions netwerk/base/nsNetUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "nsNetUtil.h"

#include "mozilla/AppShutdown.h"
#include "mozilla/Atomics.h"
#include "mozilla/BasePrincipal.h"
#include "mozilla/Components.h"
Expand Down Expand Up @@ -2709,6 +2710,11 @@ void net_EnsurePSMInit() {
return;
}

// Avoid a late initialization
if (AppShutdown::IsInOrBeyond(ShutdownPhase::AppShutdownNetTeardown)) {
return;
}

MOZ_ASSERT(XRE_IsParentProcess());
MOZ_ASSERT(NS_IsMainThread());

Expand Down
6 changes: 6 additions & 0 deletions netwerk/protocol/http/nsHttpHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
#include "mozilla/net/SocketProcessParent.h"
#include "mozilla/net/SocketProcessChild.h"
#include "mozilla/ipc/URIUtils.h"
#include "mozilla/AppShutdown.h"
#include "mozilla/Telemetry.h"
#include "mozilla/Unused.h"
#include "mozilla/AntiTrackingRedirectHeuristic.h"
Expand Down Expand Up @@ -2059,6 +2060,11 @@ nsHttpHandler::NewProxiedChannel(nsIURI* uri, nsIProxyInfo* givenProxyInfo,
httpChannel = new nsHttpChannel();
}

// Avoid a late initialization
if (AppShutdown::IsInOrBeyond(ShutdownPhase::AppShutdownNetTeardown)) {
return NS_ERROR_ILLEGAL_DURING_SHUTDOWN;
}

return SetupChannelInternal(httpChannel, uri, givenProxyInfo,
proxyResolveFlags, proxyURI, aLoadInfo, result);
}
Expand Down
5 changes: 5 additions & 0 deletions security/manager/ssl/nsNSSComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2246,6 +2246,11 @@ nsresult nsNSSComponent::Init() {
return NS_ERROR_NOT_AVAILABLE;
}

// Avoid a late initialization
if (AppShutdown::IsInOrBeyond(ShutdownPhase::AppShutdownNetTeardown)) {
return NS_ERROR_ILLEGAL_DURING_SHUTDOWN;
}

Telemetry::AutoScalarTimer<Telemetry::ScalarID::NETWORKING_NSS_INITIALIZATION>
timer;

Expand Down

0 comments on commit ea4d1a5

Please sign in to comment.