From 3e97f76a3378680345d8ab83ec5e6e429c49f4b9 Mon Sep 17 00:00:00 2001 From: Katayama Hirofumi MZ Date: Tue, 14 May 2024 23:00:54 +0900 Subject: [PATCH] [SHELL32] ShellExecute: Re-work Part 2 (#6882) Follow-up to #6871. Reduce indentation level. JIRA issue: CORE-17482 In ShellExecuteExW, early check the structure size and return on failure before SHCoInitializeAnyApartment call. --- dll/win32/shell32/shlexec.cpp | 59 +++++++++++++++++------------------ 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/dll/win32/shell32/shlexec.cpp b/dll/win32/shell32/shlexec.cpp index 492d1968208..23d0ab52df8 100644 --- a/dll/win32/shell32/shlexec.cpp +++ b/dll/win32/shell32/shlexec.cpp @@ -2431,44 +2431,43 @@ ShellExecuteExW(LPSHELLEXECUTEINFOW sei) DWORD dwError; ULONG fOldMask; - hrCoInit = SHCoInitializeAnyApartment(); - if (sei->cbSize != sizeof(SHELLEXECUTEINFOW)) { - dwError = ERROR_ACCESS_DENIED; - sei->hInstApp = (HINSTANCE)ERROR_ACCESS_DENIED; + sei->hInstApp = (HINSTANCE)UlongToHandle(SE_ERR_ACCESSDENIED); + SetLastError(ERROR_ACCESS_DENIED); + return FALSE; } - else + + hrCoInit = SHCoInitializeAnyApartment(); + + if (SHRegGetBoolUSValueW(L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer", + L"MaximizeApps", FALSE, FALSE)) { - if (SHRegGetBoolUSValueW(L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer", - L"MaximizeApps", FALSE, FALSE)) + switch (sei->nShow) { - switch (sei->nShow) - { - case SW_SHOW: - case SW_SHOWDEFAULT: - case SW_SHOWNORMAL: - case SW_RESTORE: - sei->nShow = SW_SHOWMAXIMIZED; - break; - default: - break; - } + case SW_SHOW: + case SW_SHOWDEFAULT: + case SW_SHOWNORMAL: + case SW_RESTORE: + sei->nShow = SW_SHOWMAXIMIZED; + break; + default: + break; } - - fOldMask = sei->fMask; - - if (!(fOldMask & SEE_MASK_NOASYNC) && SHELL_InRunDllProcess()) - sei->fMask |= SEE_MASK_WAITFORINPUTIDLE | SEE_MASK_NOASYNC; - - dwError = ShellExecute_Normal(sei); - - if (dwError && dwError != ERROR_DLL_NOT_FOUND && dwError != ERROR_CANCELLED) - ShellExecute_ShowError(sei, NULL, dwError); - - sei->fMask = fOldMask; } + fOldMask = sei->fMask; + + if (!(fOldMask & SEE_MASK_NOASYNC) && SHELL_InRunDllProcess()) + sei->fMask |= SEE_MASK_WAITFORINPUTIDLE | SEE_MASK_NOASYNC; + + dwError = ShellExecute_Normal(sei); + + if (dwError && dwError != ERROR_DLL_NOT_FOUND && dwError != ERROR_CANCELLED) + ShellExecute_ShowError(sei, NULL, dwError); + + sei->fMask = fOldMask; + if (SUCCEEDED(hrCoInit)) CoUninitialize();