mirror of
https://github.com/microsoft/PowerToys
synced 2025-09-01 23:15:18 +00: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:
@@ -242,11 +242,10 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Pass local app data of the current user to the service
|
// 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));
|
winrt::check_hresult(SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, nullptr, &cLocalAppPath));
|
||||||
CoTaskMemFree(cLocalAppPath);
|
|
||||||
|
|
||||||
std::wstring localAppPath{ cLocalAppPath };
|
std::wstring localAppPath{ cLocalAppPath.get() };
|
||||||
std::wstring binaryWithArgsPath = L"\"";
|
std::wstring binaryWithArgsPath = L"\"";
|
||||||
binaryWithArgsPath += servicePath;
|
binaryWithArgsPath += servicePath;
|
||||||
binaryWithArgsPath += L"\" ";
|
binaryWithArgsPath += L"\" ";
|
||||||
@@ -259,7 +258,8 @@ private:
|
|||||||
std::wstring_view existingServicePath{ pServiceConfig->lpBinaryPathName };
|
std::wstring_view existingServicePath{ pServiceConfig->lpBinaryPathName };
|
||||||
alreadyRegistered = true;
|
alreadyRegistered = true;
|
||||||
isServicePathCorrect = (existingServicePath == binaryWithArgsPath);
|
isServicePathCorrect = (existingServicePath == binaryWithArgsPath);
|
||||||
if (isServicePathCorrect) {
|
if (isServicePathCorrect)
|
||||||
|
{
|
||||||
Logger::warn(L"The service path is not correct. Current: {} Expected: {}", existingServicePath, binaryWithArgsPath);
|
Logger::warn(L"The service path is not correct. Current: {} Expected: {}", existingServicePath, binaryWithArgsPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -291,7 +291,8 @@ private:
|
|||||||
|
|
||||||
if (alreadyRegistered)
|
if (alreadyRegistered)
|
||||||
{
|
{
|
||||||
if (!isServicePathCorrect) {
|
if (!isServicePathCorrect)
|
||||||
|
{
|
||||||
if (!ChangeServiceConfigW(schService,
|
if (!ChangeServiceConfigW(schService,
|
||||||
SERVICE_NO_CHANGE,
|
SERVICE_NO_CHANGE,
|
||||||
SERVICE_NO_CHANGE,
|
SERVICE_NO_CHANGE,
|
||||||
|
Reference in New Issue
Block a user