Skip to content

Commit 3492d6b

Browse files
Ben HillisCopilot
andcommitted
Clear g_pluginHost on destruction, remove unused parameter
- Null out g_pluginHost in destructor so late plugin API calls fail with E_UNEXPECTED instead of UAF. - Remove unused lpCmdLine parameter name in wWinMain. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent d117e26 commit 3492d6b

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/windows/wslpluginhost/exe/PluginHost.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,14 @@ static std::atomic<DWORD> g_hookThreadId{0};
3333

3434
PluginHost::~PluginHost()
3535
{
36+
// Clear globally reachable state so late plugin API calls fail with
37+
// E_UNEXPECTED instead of dereferencing freed memory.
38+
if (g_pluginHost == this)
39+
{
40+
g_pluginHost = nullptr;
41+
}
42+
3643
// Module unloads automatically via wil::unique_hmodule destructor.
37-
// g_pluginHost is not cleared here — the COM ref count reaching zero means
38-
// no hooks are in-flight, and the process is about to exit (REGCLS_SINGLEUSE).
3944

4045
// Decrement the COM server reference count. When it reaches zero,
4146
// the process will exit. Matches AddComRef() in PluginHostFactory::CreateInstance.

src/windows/wslpluginhost/exe/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class PluginHostFactory : public RuntimeClass<RuntimeClassFlags<ClassicCom>, ICl
7575
}
7676
};
7777

78-
int WINAPI wWinMain(_In_ HINSTANCE, _In_opt_ HINSTANCE, _In_ LPWSTR lpCmdLine, _In_ int)
78+
int WINAPI wWinMain(_In_ HINSTANCE, _In_opt_ HINSTANCE, _In_ LPWSTR, _In_ int)
7979
try
8080
{
8181
wsl::windows::common::wslutil::ConfigureCrt();

0 commit comments

Comments
 (0)