From e1b47eb05bc1c6cd0024ead34dbee365dfe35016 Mon Sep 17 00:00:00 2001 From: Paul Purifoy <33183370+pmpurifoy@users.noreply.github.com> Date: Tue, 15 Mar 2022 15:55:45 -0700 Subject: [PATCH] Fix bug in GetExeNameFromFilePath (#2268) * Update PushNotificationUtility.h * Update PushNotificationUtility.h --- dev/PushNotifications/PushNotificationUtility.h | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/dev/PushNotifications/PushNotificationUtility.h b/dev/PushNotifications/PushNotificationUtility.h index 3aa8981d2c..55feec44f6 100644 --- a/dev/PushNotifications/PushNotificationUtility.h +++ b/dev/PushNotifications/PushNotificationUtility.h @@ -9,6 +9,7 @@ #include "wil/stl.h" #include "wil/win32_helpers.h" #include "PushBackgroundTaskInstance.h" +#include namespace winrt { @@ -155,13 +156,6 @@ namespace winrt::Microsoft::Windows::PushNotifications::Helpers } CATCH_RETURN() - inline std::wstring GetExeNameFromPath(std::wstring const& exePath) - { - size_t pos{ exePath.rfind(L"\\") }; - THROW_HR_IF(E_UNEXPECTED, pos == std::wstring::npos); - return exePath.substr(pos + 1); // One after the delimiter - } - inline winrt::guid GetComRegistrationFromRegistry(const std::wstring argumentToCheck) { wil::unique_cotaskmem_string packagedFullName; @@ -247,12 +241,12 @@ namespace winrt::Microsoft::Windows::PushNotifications::Helpers &exeBuffer, &exeBufferLength)); - std::wstring exeString{ GetExeNameFromPath(exeBuffer) }; + std::wstring exeString{ std::filesystem::path(exeBuffer).filename() }; wil::unique_cotaskmem_string exePath; THROW_IF_FAILED(wil::GetModuleFileNameExW(GetCurrentProcess(), nullptr, exePath)); - std::wstring exeToCheck{ GetExeNameFromPath(exePath.get()) }; + std::wstring exeToCheck{ std::filesystem::path(exePath.get()).filename() }; THROW_HR_IF_MSG(E_FAIL, exeString != exeToCheck, "Caller RegistrationProcess is not the same as manifest defined COM Server!");