Bug 1688387 - UntrustedModulesFixture expects to load modules listed on the blocklist. r=mhowell

In GTest of the CCov build, UntrustedModulesFixture test detected the following
modules which were loaded by the TestDllBlocklist.* tests in the same process.

  - TestDllBlocklist_MatchByName.dll
  - TestDllBlocklist_MatchByVersion.dll
  - TestDllBlocklist_NoOpEntryPoint.dll

Since they are loaded in a different thread from the one running
UntrustedModulesFixture and are blocked/redirected by our blocklist,
UntrustedModulesFixture needs to verify its loading result differently.
This patch defines an array of the expected results of these modules.

Differential Revision: https://phabricator.services.mozilla.com/D103073
This commit is contained in:
Toshihito Kikuchi 2021-01-26 18:42:50 +00:00
Родитель 119a94bbef
Коммит 382db1105f
1 изменённых файлов: 36 добавлений и 2 удалений

Просмотреть файл

@ -6,6 +6,7 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "js/RegExp.h" #include "js/RegExp.h"
#include "mozilla/BinarySearch.h"
#include "mozilla/SpinEventLoopUntil.h" #include "mozilla/SpinEventLoopUntil.h"
#include "mozilla/UntrustedModulesProcessor.h" #include "mozilla/UntrustedModulesProcessor.h"
#include "mozilla/WinDllServices.h" #include "mozilla/WinDllServices.h"
@ -135,6 +136,22 @@ class UntrustedModulesCollector {
}; };
static void ValidateUntrustedModules(const UntrustedModulesData& aData) { static void ValidateUntrustedModules(const UntrustedModulesData& aData) {
// This defines a list of modules which are listed on our blocklist and
// thus its loading status is not expected to be Status::Loaded.
// Although the UntrustedModulesFixture test does not touch any of them,
// the current process might have run a test like TestDllBlocklist where
// we try to load and block them.
const struct {
const wchar_t* mName;
ModuleLoadInfo::Status mStatus;
} kKnownModules[] = {
// Sorted by mName for binary-search
{L"TestDllBlocklist_MatchByName.dll", ModuleLoadInfo::Status::Blocked},
{L"TestDllBlocklist_MatchByVersion.dll", ModuleLoadInfo::Status::Blocked},
{L"TestDllBlocklist_NoOpEntryPoint.dll",
ModuleLoadInfo::Status::Redirected},
};
EXPECT_EQ(aData.mProcessType, GeckoProcessType_Default); EXPECT_EQ(aData.mProcessType, GeckoProcessType_Default);
EXPECT_EQ(aData.mPid, ::GetCurrentProcessId()); EXPECT_EQ(aData.mPid, ::GetCurrentProcessId());
@ -145,11 +162,28 @@ static void ValidateUntrustedModules(const UntrustedModulesData& aData) {
} }
for (const auto& evt : aData.mEvents) { for (const auto& evt : aData.mEvents) {
EXPECT_EQ(evt.mThreadId, ::GetCurrentThreadId()); const nsDependentSubstring leafName =
nt::GetLeafName(evt.mModule->mResolvedNtName);
const nsAutoString leafNameStr(leafName.Data(), leafName.Length());
size_t match;
if (BinarySearchIf(
kKnownModules, 0, ArrayLength(kKnownModules),
[&leafNameStr](const auto& aVal) {
return _wcsicmp(leafNameStr.get(), aVal.mName);
},
&match)) {
// No check for mThreadId because a known module may be loaded
// in a different thread.
EXPECT_EQ(evt.mLoadStatus,
static_cast<uint32_t>(kKnownModules[match].mStatus));
} else {
EXPECT_EQ(evt.mThreadId, ::GetCurrentThreadId());
EXPECT_EQ(evt.mLoadStatus, 0);
}
// Make sure mModule is pointing to an entry of mModules. // Make sure mModule is pointing to an entry of mModules.
EXPECT_TRUE(moduleSet.Contains(evt.mModule)); EXPECT_TRUE(moduleSet.Contains(evt.mModule));
EXPECT_FALSE(evt.mIsDependent); EXPECT_FALSE(evt.mIsDependent);
EXPECT_EQ(evt.mLoadStatus, 0);
} }
// No check for the mXULLoadDurationMS field because the field has a value // No check for the mXULLoadDurationMS field because the field has a value