]> repos.lx-s.de Git - winmute.git/commitdiff
Hardened program loading.
authorlx-s <lx-s@users.noreply.github.com>
Wed, 8 Jul 2026 07:35:00 +0000 (09:35 +0200)
committerlx-s <lx-s@users.noreply.github.com>
Wed, 8 Jul 2026 07:35:00 +0000 (09:35 +0200)
WinMute/WinMain.cpp

index 6602781f1ed1836ea13d16d550d3e87b0a8e252f..a3051e9b954ac729fc765f07ae50cba942ed6683 100644 (file)
@@ -93,6 +93,10 @@ int WINAPI wWinMain(
    _In_ PWSTR,
    _In_ int)
 {
+   // Harden the DLL search path against binary planting before anything
+   // is loaded dynamically.
+   SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_SYSTEM32);
+
    hglobInstance = hInstance;
    WMSettings settings;
    WMi18n& i18n = WMi18n::GetInstance();
@@ -152,7 +156,14 @@ int WINAPI wWinMain(
    MSG msg = { nullptr };
    WinMute program(settings);
    if (program.Init()) {
-      while (GetMessage(&msg, nullptr, 0, 0)) {
+      for (;;) {
+         const BOOL msgResult = GetMessage(&msg, nullptr, 0, 0);
+         if (msgResult == 0) { // WM_QUIT
+            break;
+         } else if (msgResult == -1) {
+            WMLog::GetInstance().LogWinError(L"GetMessage", GetLastError());
+            break;
+         }
          HWND hwnd = GetForegroundWindow();
          if (!IsWindow(hwnd) || !IsDialogMessage(hwnd, &msg)) {
             TranslateMessage(&msg);