Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move regex init for compat #13

Merged
merged 1 commit into from
Jan 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 additions & 11 deletions vfdynf/vrf_fault.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct GlobalContext
std::mutex Lock;
uint64_t LastClear = 0;
std::unordered_map<uint32_t, StackEntry> StackTable;
std::once_flag ExclusionsRegexOnce;
bool ExclusionsRegexInitialized = false;
std::vector<std::wregex> ExclusionsRegex;
};

Expand Down Expand Up @@ -96,18 +96,18 @@ SymbolRegsteredCallback(
}

static
void
bool
InitExclusionsRegex(
void
)
_In_ GlobalContext* Context
) noexcept
{
//
// The exclusions regular expressions is a REG_MULTI_SZ from the properties
// verifier loads on our behalf. Parse each block of the multi terminated
// string into the regex vector. We do this so we don't have to construct
// the regex object every time. This is called once during the first
// evaluation.
// the regex object every time.
//
assert(!Context->ExclusionsRegexInitialized);

size_t offset = 0;
for (;;)
Expand All @@ -121,10 +121,10 @@ InitExclusionsRegex(

try
{
g_Context->ExclusionsRegex.emplace_back(expr.Buffer,
expr.Length / sizeof(WCHAR),
(std::wregex::ECMAScript |
std::wregex::optimize));
Context->ExclusionsRegex.emplace_back(expr.Buffer,
expr.Length / sizeof(WCHAR),
(std::wregex::ECMAScript |
std::wregex::optimize));
}
catch (const std::exception& exc)
{
Expand All @@ -133,10 +133,14 @@ InitExclusionsRegex(
"AVRF: exception (%s) raised processing regex!\n",
exc.what());
__debugbreak();
return false;
}

offset += ((expr.Length / sizeof(WCHAR)) + 1);
}

Context->ExclusionsRegexInitialized = true;
return true;
}

static
Expand All @@ -145,7 +149,7 @@ IsStackOverriddenByRegex(
_In_ const std::wstring& StackSymbols
)
{
std::call_once(g_Context->ExclusionsRegexOnce, InitExclusionsRegex);
assert(g_Context->ExclusionsRegexInitialized);

for (const auto& entry : g_Context->ExclusionsRegex)
{
Expand Down Expand Up @@ -480,6 +484,16 @@ fault::ProcessAttach(
return false;
}

if (!InitExclusionsRegex(context.get()))
{
DbgPrintEx(DPFLTR_VERIFIER_ID,
DPFLTR_ERROR_LEVEL,
"AVRF: failed to initialized exclusions regex!\n");

__debugbreak();
return false;
}

if (g_Properties.SymbolSearchPath[0] == L'\0')
{
if (SymInitializeW(NtCurrentProcess(), nullptr, FALSE) == FALSE)
Expand Down