Skip to content

Commit

Permalink
Bug 1542214 - Prevent registering the same CID and contract IDs durin…
Browse files Browse the repository at this point in the history
…g component manager initialization. r=froydnj

Because not all static components are using the static registration yet,
we can end up in situations where a same component is registered
multiple times, which can have some unexpected consequences.

Interestingly enough, this change revealed that we did have static
registration in place for components that were kept under the old system
after bug 1478124 and bug 1524687.

There are also possibly some non-obvious things that can happen while
migrating the remaining components, like what happened to me while I
worked on @mozilla.org/widget/components;1 (see bug 1542214 comment 0).

Differential Revision: https://phabricator.services.mozilla.com/D26698

--HG--
extra : moz-landing-system : lando
  • Loading branch information
glandium committed Apr 9, 2019
1 parent d452755 commit 5c5f0f8
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions xpcom/components/nsComponentManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,19 @@ void nsComponentManagerImpl::RegisterCIDEntryLocked(
return;
}

#ifdef DEBUG
// If we're still in the static initialization phase, check that we're not
// registering something that was already registered.
if (mStatus != NORMAL) {
if (StaticComponents::LookupByCID(*aEntry->cid)) {
MOZ_CRASH_UNSAFE_PRINTF(
"While registering XPCOM module %s, trying to re-register CID '%s' "
"already registered by a static component.",
aModule->Description().get(), AutoIDString(*aEntry->cid).get());
}
}
#endif

if (auto entry = mFactories.LookupForAdd(aEntry->cid)) {
nsFactoryEntry* f = entry.Data();
NS_WARNING("Re-registering a CID?");
Expand Down Expand Up @@ -740,6 +753,21 @@ void nsComponentManagerImpl::RegisterContractIDLocked(
return;
}

#ifdef DEBUG
// If we're still in the static initialization phase, check that we're not
// registering something that was already registered.
if (mStatus != NORMAL) {
if (const StaticModule* module = StaticComponents::LookupByContractID(
nsAutoCString(aEntry->contractid))) {
MOZ_CRASH_UNSAFE_PRINTF(
"Could not map contract ID '%s' to CID %s because it is already "
"mapped to CID %s.",
aEntry->contractid, AutoIDString(*aEntry->cid).get(),
AutoIDString(module->CID()).get());
}
}
#endif

nsFactoryEntry* f = mFactories.Get(aEntry->cid);
if (!f) {
NS_WARNING("No CID found when attempting to map contract ID");
Expand Down

0 comments on commit 5c5f0f8

Please sign in to comment.