mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-11-27 23:19:13 +08:00
[MWB] Fix use after free in service registration (#31633)
* [MWB] Fix use after free in service registration * Update src/modules/MouseWithoutBorders/ModuleInterface/dllmain.cpp --------- Co-authored-by: Andrey Nekrasov <1828123+yuyoyuppe@users.noreply.github.com>
This commit is contained in:
parent
eeedbc7982
commit
70d790cfde
@ -198,7 +198,7 @@ private:
|
||||
Logger::error("Failed to delete MWB service");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Trace::MouseWithoutBorders::ToggleServiceRegistration(false);
|
||||
}
|
||||
|
||||
@ -242,11 +242,10 @@ private:
|
||||
}
|
||||
|
||||
// Pass local app data of the current user to the service
|
||||
PWSTR cLocalAppPath;
|
||||
wil::unique_cotaskmem_string cLocalAppPath;
|
||||
winrt::check_hresult(SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, nullptr, &cLocalAppPath));
|
||||
CoTaskMemFree(cLocalAppPath);
|
||||
|
||||
std::wstring localAppPath{ cLocalAppPath };
|
||||
std::wstring localAppPath{ cLocalAppPath.get() };
|
||||
std::wstring binaryWithArgsPath = L"\"";
|
||||
binaryWithArgsPath += servicePath;
|
||||
binaryWithArgsPath += L"\" ";
|
||||
@ -259,7 +258,8 @@ private:
|
||||
std::wstring_view existingServicePath{ pServiceConfig->lpBinaryPathName };
|
||||
alreadyRegistered = true;
|
||||
isServicePathCorrect = (existingServicePath == binaryWithArgsPath);
|
||||
if (isServicePathCorrect) {
|
||||
if (isServicePathCorrect)
|
||||
{
|
||||
Logger::warn(L"The service path is not correct. Current: {} Expected: {}", existingServicePath, binaryWithArgsPath);
|
||||
}
|
||||
|
||||
@ -291,18 +291,19 @@ private:
|
||||
|
||||
if (alreadyRegistered)
|
||||
{
|
||||
if (!isServicePathCorrect) {
|
||||
if (!isServicePathCorrect)
|
||||
{
|
||||
if (!ChangeServiceConfigW(schService,
|
||||
SERVICE_NO_CHANGE,
|
||||
SERVICE_NO_CHANGE,
|
||||
SERVICE_NO_CHANGE,
|
||||
binaryWithArgsPath.c_str(),
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr))
|
||||
SERVICE_NO_CHANGE,
|
||||
SERVICE_NO_CHANGE,
|
||||
SERVICE_NO_CHANGE,
|
||||
binaryWithArgsPath.c_str(),
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr))
|
||||
{
|
||||
Logger::error(L"Failed to update the service's path. ERROR: {}", GetLastError());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user