Fix wslsettings crash when invoked from wslservice (#13089)

This commit is contained in:
Blue 2025-06-11 15:06:04 -07:00 committed by GitHub
parent 71daaef7bb
commit 5d20b44bc6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 2 deletions

View File

@ -92,8 +92,7 @@ public:
[[nodiscard]] wil::unique_handle Launch(_In_opt_ HANDLE UserToken, _In_ bool HideWindow, _In_ bool CreateNoWindow = false) const
{
// If a user token was provided, create an environment block from the token.
using unique_environment_block = wil::unique_any<LPVOID, decltype(&DestroyEnvironmentBlock), DestroyEnvironmentBlock>;
unique_environment_block environmentBlock{nullptr};
wsl::windows::common::helpers::unique_environment_block environmentBlock{nullptr};
if (ARGUMENT_PRESENT(UserToken))
{
THROW_LAST_ERROR_IF(!CreateEnvironmentBlock(&environmentBlock, UserToken, false));
@ -572,6 +571,12 @@ void wsl::windows::common::helpers::LaunchWslSettingsOOBE(_In_ HANDLE UserToken)
wsl::windows::common::SubProcess process(wslSettingsExePath.c_str(), commandLine);
process.SetToken(UserToken);
process.SetShowWindow(SW_SHOW);
wsl::windows::common::helpers::unique_environment_block environmentBlock{nullptr};
THROW_LAST_ERROR_IF(!CreateEnvironmentBlock(&environmentBlock, UserToken, false));
process.SetEnvironment(environmentBlock.get());
process.Start();
}

View File

@ -92,6 +92,8 @@ struct GuidLess
typedef wil::unique_any_handle_null<decltype(&::ClosePseudoConsole), ::ClosePseudoConsole> unique_pseudo_console;
using unique_environment_block = wil::unique_any<LPVOID, decltype(&DestroyEnvironmentBlock), DestroyEnvironmentBlock>;
inline void DeleteProcThreadAttributeList(_In_ PPROC_THREAD_ATTRIBUTE_LIST AttributeList)
{
::DeleteProcThreadAttributeList(AttributeList);