From e78138558fe17d8a91929c87b2a6d0c9a482d78a Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Wed, 28 Apr 2021 16:43:01 -0500 Subject: Clean up 32-bit assumptions. --- src/engine/cache.cpp | 12 ++-- src/engine/condition.cpp | 24 ++++++- src/engine/core.cpp | 9 ++- src/engine/elevation.cpp | 90 +++++++++++++------------ src/engine/embedded.cpp | 8 +-- src/engine/engine.cpp | 9 ++- src/engine/engine.vcxproj | 4 +- src/engine/exeengine.cpp | 2 +- src/engine/logging.cpp | 6 +- src/engine/packages.config | 2 +- src/engine/pipe.cpp | 105 ++++++++--------------------- src/engine/pipe.h | 2 +- src/engine/variable.cpp | 2 +- src/stub/packages.config | 2 +- src/stub/stub.vcxproj | 4 +- src/test/BurnUnitTest/BurnUnitTest.vcxproj | 16 ++--- src/test/BurnUnitTest/packages.config | 6 +- 17 files changed, 139 insertions(+), 164 deletions(-) diff --git a/src/engine/cache.cpp b/src/engine/cache.cpp index fcc7f72d..59daf139 100644 --- a/src/engine/cache.cpp +++ b/src/engine/cache.cpp @@ -1119,7 +1119,7 @@ extern "C" void CacheCleanup( LPWSTR sczDelete = NULL; HANDLE hFind = INVALID_HANDLE_VALUE; WIN32_FIND_DATAW wfd = { }; - DWORD cFileName = 0; + size_t cchFileName = 0; hr = CacheGetCompletedPath(fPerMachine, UNVERIFIED_CACHE_FOLDER_NAME, &sczFolder); if (SUCCEEDED(hr)) @@ -1146,17 +1146,15 @@ extern "C" void CacheCleanup( continue; } - // For extra safety and to silence OACR. - wfd.cFileName[MAX_PATH - 1] = L'\0'; - // Skip resume files (they end with ".R"). - cFileName = lstrlenW(wfd.cFileName); - if (2 < cFileName && L'.' == wfd.cFileName[cFileName - 2] && (L'R' == wfd.cFileName[cFileName - 1] || L'r' == wfd.cFileName[cFileName - 1])) + hr = ::StringCchLengthW(wfd.cFileName, MAX_PATH, &cchFileName); + if (FAILED(hr) || + 2 < cchFileName && L'.' == wfd.cFileName[cchFileName - 2] && (L'R' == wfd.cFileName[cchFileName - 1] || L'r' == wfd.cFileName[cchFileName - 1])) { continue; } - hr = PathConcat(sczFolder, wfd.cFileName, &sczDelete); + hr = PathConcatCch(sczFolder, 0, wfd.cFileName, cchFileName, &sczDelete); if (SUCCEEDED(hr)) { hr = FileEnsureDelete(sczDelete); diff --git a/src/engine/condition.cpp b/src/engine/condition.cpp index 56fe76c2..b7cd7413 100644 --- a/src/engine/condition.cpp +++ b/src/engine/condition.cpp @@ -513,6 +513,7 @@ static HRESULT NextSymbol( { HRESULT hr = S_OK; WORD charType = 0; + ptrdiff_t cchPosition = 0; DWORD iPosition = 0; DWORD n = 0; @@ -530,7 +531,13 @@ static HRESULT NextSymbol( } ++pContext->wzRead; } - iPosition = (DWORD)(pContext->wzRead - pContext->wzCondition); + + cchPosition = pContext->wzRead - pContext->wzCondition; + if (DWORD_MAX < cchPosition || 0 > cchPosition) + { + ExitOnFailure(hr = E_INVALIDARG, "Symbol was too long: %ls", pContext->wzCondition); + } + iPosition = (DWORD)cchPosition; // read depending on first character type switch (pContext->wzRead[0]) @@ -922,8 +929,19 @@ static HRESULT CompareStringValues( { HRESULT hr = S_OK; DWORD dwCompareString = (comparison & INSENSITIVE) ? NORM_IGNORECASE : 0; - int cchLeft = lstrlenW(wzLeftOperand); - int cchRight = lstrlenW(wzRightOperand); + size_t cchLeftSize = 0; + size_t cchRightSize = 0; + int cchLeft = 0; + int cchRight = 0; + + hr = ::StringCchLengthW(wzLeftOperand, STRSAFE_MAX_CCH, &cchLeftSize); + ExitOnRootFailure(hr, "Failed to get length of left string: %ls", wzLeftOperand); + + hr = ::StringCchLengthW(wzRightOperand, STRSAFE_MAX_CCH, &cchRightSize); + ExitOnRootFailure(hr, "Failed to get length of right string: %ls", wzRightOperand); + + cchLeft = static_cast(cchLeftSize); + cchRight = static_cast(cchRightSize); switch (comparison) { diff --git a/src/engine/core.cpp b/src/engine/core.cpp index 969b94a0..a915dad0 100644 --- a/src/engine/core.cpp +++ b/src/engine/core.cpp @@ -1050,7 +1050,7 @@ extern "C" HRESULT CoreAppendFileHandleAttachedToCommandLine( ExitWithLastError(hr, "Failed to duplicate file handle for attached container."); } - hr = StrAllocFormattedSecure(psczCommandLine, L"%ls -%ls=%u", *psczCommandLine, BURN_COMMANDLINE_SWITCH_FILEHANDLE_ATTACHED, hExecutableFile); + hr = StrAllocFormattedSecure(psczCommandLine, L"%ls -%ls=%Iu", *psczCommandLine, BURN_COMMANDLINE_SWITCH_FILEHANDLE_ATTACHED, reinterpret_cast(hExecutableFile)); ExitOnFailure(hr, "Failed to append the file handle to the command line."); *phExecutableFile = hExecutableFile; @@ -1078,12 +1078,12 @@ extern "C" HRESULT CoreAppendFileHandleSelfToCommandLine( hExecutableFile = ::CreateFileW(wzExecutablePath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_DELETE, &securityAttributes, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (INVALID_HANDLE_VALUE != hExecutableFile) { - hr = StrAllocFormattedSecure(psczCommandLine, L"%ls -%ls=%u", *psczCommandLine, BURN_COMMANDLINE_SWITCH_FILEHANDLE_SELF, hExecutableFile); + hr = StrAllocFormattedSecure(psczCommandLine, L"%ls -%ls=%Iu", *psczCommandLine, BURN_COMMANDLINE_SWITCH_FILEHANDLE_SELF, reinterpret_cast(hExecutableFile)); ExitOnFailure(hr, "Failed to append the file handle to the command line."); if (psczObfuscatedCommandLine) { - hr = StrAllocFormatted(psczObfuscatedCommandLine, L"%ls -%ls=%u", *psczObfuscatedCommandLine, BURN_COMMANDLINE_SWITCH_FILEHANDLE_SELF, hExecutableFile); + hr = StrAllocFormatted(psczObfuscatedCommandLine, L"%ls -%ls=%Iu", *psczObfuscatedCommandLine, BURN_COMMANDLINE_SWITCH_FILEHANDLE_SELF, reinterpret_cast(hExecutableFile)); ExitOnFailure(hr, "Failed to append the file handle to the obfuscated command line."); } @@ -1499,8 +1499,7 @@ static HRESULT ParseCommandLine( { // Already processed in InitializeEngineState. } - else if (lstrlenW(&argv[i][1]) >= lstrlenW(BURN_COMMANDLINE_SWITCH_PREFIX) && - CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, &argv[i][1], lstrlenW(BURN_COMMANDLINE_SWITCH_PREFIX), BURN_COMMANDLINE_SWITCH_PREFIX, lstrlenW(BURN_COMMANDLINE_SWITCH_PREFIX))) + else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, &argv[i][1], lstrlenW(BURN_COMMANDLINE_SWITCH_PREFIX), BURN_COMMANDLINE_SWITCH_PREFIX, lstrlenW(BURN_COMMANDLINE_SWITCH_PREFIX))) { // Skip (but log) any other private burn switches we don't recognize, so that // adding future private variables doesn't break old bundles diff --git a/src/engine/elevation.cpp b/src/engine/elevation.cpp index 3a448923..9d1b8fc7 100644 --- a/src/engine/elevation.cpp +++ b/src/engine/elevation.cpp @@ -157,7 +157,7 @@ static HRESULT OnApplyInitialize( __in HANDLE* phLock, __in BOOL* pfDisabledWindowsUpdate, __in BYTE* pbData, - __in DWORD cbData + __in SIZE_T cbData ); static HRESULT OnApplyUninitialize( __in HANDLE* phLock @@ -166,39 +166,39 @@ static HRESULT OnSessionBegin( __in BURN_REGISTRATION* pRegistration, __in BURN_VARIABLES* pVariables, __in BYTE* pbData, - __in DWORD cbData + __in SIZE_T cbData ); static HRESULT OnSessionResume( __in BURN_REGISTRATION* pRegistration, __in BURN_VARIABLES* pVariables, __in BYTE* pbData, - __in DWORD cbData + __in SIZE_T cbData ); static HRESULT OnSessionEnd( __in BURN_PACKAGES* pPackages, __in BURN_REGISTRATION* pRegistration, __in BURN_VARIABLES* pVariables, __in BYTE* pbData, - __in DWORD cbData + __in SIZE_T cbData ); static HRESULT OnSaveState( __in BURN_REGISTRATION* pRegistration, __in BYTE* pbData, - __in DWORD cbData + __in SIZE_T cbData ); static HRESULT OnCacheCompletePayload( __in HANDLE hPipe, __in BURN_PACKAGES* pPackages, __in BURN_PAYLOADS* pPayloads, __in BYTE* pbData, - __in DWORD cbData + __in SIZE_T cbData ); static HRESULT OnCacheVerifyPayload( __in HANDLE hPipe, __in BURN_PACKAGES* pPackages, __in BURN_PAYLOADS* pPayloads, __in BYTE* pbData, - __in DWORD cbData + __in SIZE_T cbData ); static void OnCacheCleanup( __in_z LPCWSTR wzBundleId @@ -206,7 +206,7 @@ static void OnCacheCleanup( static HRESULT OnProcessDependentRegistration( __in const BURN_REGISTRATION* pRegistration, __in BYTE* pbData, - __in DWORD cbData + __in SIZE_T cbData ); static HRESULT OnExecuteExePackage( __in HANDLE hPipe, @@ -214,40 +214,40 @@ static HRESULT OnExecuteExePackage( __in BURN_RELATED_BUNDLES* pRelatedBundles, __in BURN_VARIABLES* pVariables, __in BYTE* pbData, - __in DWORD cbData + __in SIZE_T cbData ); static HRESULT OnExecuteMsiPackage( __in HANDLE hPipe, __in BURN_PACKAGES* pPackages, __in BURN_VARIABLES* pVariables, __in BYTE* pbData, - __in DWORD cbData + __in SIZE_T cbData ); static HRESULT OnExecuteMspPackage( __in HANDLE hPipe, __in BURN_PACKAGES* pPackages, __in BURN_VARIABLES* pVariables, __in BYTE* pbData, - __in DWORD cbData + __in SIZE_T cbData ); static HRESULT OnExecuteMsuPackage( __in HANDLE hPipe, __in BURN_PACKAGES* pPackages, __in BURN_VARIABLES* pVariables, __in BYTE* pbData, - __in DWORD cbData + __in SIZE_T cbData ); static HRESULT OnExecutePackageProviderAction( __in BURN_PACKAGES* pPackages, __in BURN_RELATED_BUNDLES* pRelatedBundles, __in BYTE* pbData, - __in DWORD cbData + __in SIZE_T cbData ); static HRESULT OnExecutePackageDependencyAction( __in BURN_PACKAGES* pPackages, __in BURN_RELATED_BUNDLES* pRelatedBundles, __in BYTE* pbData, - __in DWORD cbData + __in SIZE_T cbData ); static HRESULT CALLBACK BurnCacheMessageHandler( __in BURN_CACHE_MESSAGE* pMessage, @@ -275,29 +275,29 @@ static int MsiExecuteMessageHandler( static HRESULT OnCleanPackage( __in BURN_PACKAGES* pPackages, __in BYTE* pbData, - __in DWORD cbData + __in SIZE_T cbData ); static HRESULT OnLaunchApprovedExe( __in HANDLE hPipe, __in BURN_APPROVED_EXES* pApprovedExes, __in BURN_VARIABLES* pVariables, __in BYTE* pbData, - __in DWORD cbData + __in SIZE_T cbData ); static HRESULT OnMsiBeginTransaction( __in BURN_PACKAGES* pPackages, __in BYTE* pbData, - __in DWORD cbData + __in SIZE_T cbData ); static HRESULT OnMsiCommitTransaction( __in BURN_PACKAGES* pPackages, __in BYTE* pbData, - __in DWORD cbData + __in SIZE_T cbData ); static HRESULT OnMsiRollbackTransaction( __in BURN_PACKAGES* pPackages, __in BYTE* pbData, - __in DWORD cbData + __in SIZE_T cbData ); static HRESULT ElevatedOnPauseAUBegin( __in HANDLE hPipe @@ -603,7 +603,7 @@ HRESULT ElevationSaveState( DWORD dwResult = 0; // send message - hr = PipeSendMessage(hPipe, BURN_ELEVATION_MESSAGE_TYPE_SAVE_STATE, pbBuffer, (DWORD)cbBuffer, NULL, NULL, &dwResult); + hr = PipeSendMessage(hPipe, BURN_ELEVATION_MESSAGE_TYPE_SAVE_STATE, pbBuffer, cbBuffer, NULL, NULL, &dwResult); ExitOnFailure(hr, "Failed to send message to per-machine process."); hr = (HRESULT)dwResult; @@ -858,6 +858,8 @@ extern "C" HRESULT ElevationMsiCommitTransaction( hr = static_cast(dwResult); LExit: + ReleaseBuffer(pbData); + return hr; } @@ -884,6 +886,8 @@ extern "C" HRESULT ElevationMsiRollbackTransaction( hr = static_cast(dwResult); LExit: + ReleaseBuffer(pbData); + return hr; } @@ -1612,7 +1616,7 @@ static HRESULT ProcessMsiPackageMessages( message.rgwzData = (LPCWSTR*)rgwzMsiData; } - hr = BuffReadNumber((BYTE*)pMsg->pvData, pMsg->cbData, &iData, (DWORD*)&message.dwAllowedResults); + hr = BuffReadNumber((BYTE*)pMsg->pvData, pMsg->cbData, &iData, &message.dwAllowedResults); ExitOnFailure(hr, "Failed to read UI flags."); // Process the rest of the message. @@ -1907,7 +1911,7 @@ static HRESULT OnApplyInitialize( __in HANDLE* phLock, __in BOOL* pfDisabledWindowsUpdate, __in BYTE* pbData, - __in DWORD cbData + __in SIZE_T cbData ) { HRESULT hr = S_OK; @@ -2031,7 +2035,7 @@ static HRESULT OnSessionBegin( __in BURN_REGISTRATION* pRegistration, __in BURN_VARIABLES* pVariables, __in BYTE* pbData, - __in DWORD cbData + __in SIZE_T cbData ) { HRESULT hr = S_OK; @@ -2077,7 +2081,7 @@ static HRESULT OnSessionResume( __in BURN_REGISTRATION* pRegistration, __in BURN_VARIABLES* pVariables, __in BYTE* pbData, - __in DWORD cbData + __in SIZE_T cbData ) { HRESULT hr = S_OK; @@ -2106,7 +2110,7 @@ static HRESULT OnSessionEnd( __in BURN_REGISTRATION* pRegistration, __in BURN_VARIABLES* pVariables, __in BYTE* pbData, - __in DWORD cbData + __in SIZE_T cbData ) { HRESULT hr = S_OK; @@ -2136,7 +2140,7 @@ LExit: static HRESULT OnSaveState( __in BURN_REGISTRATION* pRegistration, __in BYTE* pbData, - __in DWORD cbData + __in SIZE_T cbData ) { HRESULT hr = S_OK; @@ -2154,7 +2158,7 @@ static HRESULT OnCacheCompletePayload( __in BURN_PACKAGES* pPackages, __in BURN_PAYLOADS* pPayloads, __in BYTE* pbData, - __in DWORD cbData + __in SIZE_T cbData ) { HRESULT hr = S_OK; @@ -2213,7 +2217,7 @@ static HRESULT OnCacheVerifyPayload( __in BURN_PACKAGES* pPackages, __in BURN_PAYLOADS* pPayloads, __in BYTE* pbData, - __in DWORD cbData + __in SIZE_T cbData ) { HRESULT hr = S_OK; @@ -2273,7 +2277,7 @@ static void OnCacheCleanup( static HRESULT OnProcessDependentRegistration( __in const BURN_REGISTRATION* pRegistration, __in BYTE* pbData, - __in DWORD cbData + __in SIZE_T cbData ) { HRESULT hr = S_OK; @@ -2309,7 +2313,7 @@ static HRESULT OnExecuteExePackage( __in BURN_RELATED_BUNDLES* pRelatedBundles, __in BURN_VARIABLES* pVariables, __in BYTE* pbData, - __in DWORD cbData + __in SIZE_T cbData ) { HRESULT hr = S_OK; @@ -2393,7 +2397,7 @@ static HRESULT OnExecuteMsiPackage( __in BURN_PACKAGES* pPackages, __in BURN_VARIABLES* pVariables, __in BYTE* pbData, - __in DWORD cbData + __in SIZE_T cbData ) { HRESULT hr = S_OK; @@ -2490,7 +2494,7 @@ static HRESULT OnExecuteMspPackage( __in BURN_PACKAGES* pPackages, __in BURN_VARIABLES* pVariables, __in BYTE* pbData, - __in DWORD cbData + __in SIZE_T cbData ) { HRESULT hr = S_OK; @@ -2585,7 +2589,7 @@ static HRESULT OnExecuteMsuPackage( __in BURN_PACKAGES* pPackages, __in BURN_VARIABLES* pVariables, __in BYTE* pbData, - __in DWORD cbData + __in SIZE_T cbData ) { HRESULT hr = S_OK; @@ -2644,7 +2648,7 @@ static HRESULT OnExecutePackageProviderAction( __in BURN_PACKAGES* pPackages, __in BURN_RELATED_BUNDLES* pRelatedBundles, __in BYTE* pbData, - __in DWORD cbData + __in SIZE_T cbData ) { HRESULT hr = S_OK; @@ -2684,7 +2688,7 @@ static HRESULT OnExecutePackageDependencyAction( __in BURN_PACKAGES* pPackages, __in BURN_RELATED_BUNDLES* pRelatedBundles, __in BYTE* pbData, - __in DWORD cbData + __in SIZE_T cbData ) { HRESULT hr = S_OK; @@ -2953,7 +2957,7 @@ LExit: static HRESULT OnCleanPackage( __in BURN_PACKAGES* pPackages, __in BYTE* pbData, - __in DWORD cbData + __in SIZE_T cbData ) { HRESULT hr = S_OK; @@ -2982,7 +2986,7 @@ static HRESULT OnLaunchApprovedExe( __in BURN_APPROVED_EXES* pApprovedExes, __in BURN_VARIABLES* pVariables, __in BYTE* pbData, - __in DWORD cbData + __in SIZE_T cbData ) { HRESULT hr = S_OK; @@ -3051,7 +3055,7 @@ LExit: static HRESULT OnMsiBeginTransaction( __in BURN_PACKAGES* pPackages, __in BYTE* pbData, - __in DWORD cbData + __in SIZE_T cbData ) { HRESULT hr = S_OK; @@ -3067,7 +3071,7 @@ static HRESULT OnMsiBeginTransaction( hr = BuffReadString(pbData, cbData, &iData, &sczLogPath); ExitOnFailure(hr, "Failed to read transaction log path."); - PackageFindRollbackBoundaryById(pPackages, sczId, &pRollbackBoundary); + hr = PackageFindRollbackBoundaryById(pPackages, sczId, &pRollbackBoundary); ExitOnFailure(hr, "Failed to find rollback boundary: %ls", sczId); pRollbackBoundary->sczLogPath = sczLogPath; @@ -3089,7 +3093,7 @@ LExit: static HRESULT OnMsiCommitTransaction( __in BURN_PACKAGES* pPackages, __in BYTE* pbData, - __in DWORD cbData + __in SIZE_T cbData ) { HRESULT hr = S_OK; @@ -3105,7 +3109,7 @@ static HRESULT OnMsiCommitTransaction( hr = BuffReadString(pbData, cbData, &iData, &sczLogPath); ExitOnFailure(hr, "Failed to read transaction log path."); - PackageFindRollbackBoundaryById(pPackages, sczId, &pRollbackBoundary); + hr = PackageFindRollbackBoundaryById(pPackages, sczId, &pRollbackBoundary); ExitOnFailure(hr, "Failed to find rollback boundary: %ls", sczId); pRollbackBoundary->sczLogPath = sczLogPath; @@ -3127,7 +3131,7 @@ LExit: static HRESULT OnMsiRollbackTransaction( __in BURN_PACKAGES* pPackages, __in BYTE* pbData, - __in DWORD cbData + __in SIZE_T cbData ) { HRESULT hr = S_OK; @@ -3143,7 +3147,7 @@ static HRESULT OnMsiRollbackTransaction( hr = BuffReadString(pbData, cbData, &iData, &sczLogPath); ExitOnFailure(hr, "Failed to read transaction log path."); - PackageFindRollbackBoundaryById(pPackages, sczId, &pRollbackBoundary); + hr = PackageFindRollbackBoundaryById(pPackages, sczId, &pRollbackBoundary); ExitOnFailure(hr, "Failed to find rollback boundary: %ls", sczId); pRollbackBoundary->sczLogPath = sczLogPath; diff --git a/src/engine/embedded.cpp b/src/engine/embedded.cpp index b512b365..03898ebd 100644 --- a/src/engine/embedded.cpp +++ b/src/engine/embedded.cpp @@ -22,14 +22,14 @@ static HRESULT OnEmbeddedErrorMessage( __in PFN_GENERICMESSAGEHANDLER pfnMessageHandler, __in LPVOID pvContext, __in_bcount(cbData) BYTE* pbData, - __in DWORD cbData, + __in SIZE_T cbData, __out DWORD* pdwResult ); static HRESULT OnEmbeddedProgress( __in PFN_GENERICMESSAGEHANDLER pfnMessageHandler, __in LPVOID pvContext, __in_bcount(cbData) BYTE* pbData, - __in DWORD cbData, + __in SIZE_T cbData, __out DWORD* pdwResult ); @@ -142,7 +142,7 @@ static HRESULT OnEmbeddedErrorMessage( __in PFN_GENERICMESSAGEHANDLER pfnMessageHandler, __in LPVOID pvContext, __in_bcount(cbData) BYTE* pbData, - __in DWORD cbData, + __in SIZE_T cbData, __out DWORD* pdwResult ) { @@ -176,7 +176,7 @@ static HRESULT OnEmbeddedProgress( __in PFN_GENERICMESSAGEHANDLER pfnMessageHandler, __in LPVOID pvContext, __in_bcount(cbData) BYTE* pbData, - __in DWORD cbData, + __in SIZE_T cbData, __out DWORD* pdwResult ) { diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index e2728d7f..8f024e98 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -324,6 +324,7 @@ static HRESULT InitializeEngineState( LPCWSTR wzParam = NULL; HANDLE hSectionFile = hEngineFile; HANDLE hSourceEngineFile = INVALID_HANDLE_VALUE; + DWORD64 qw = 0; pEngineState->automaticUpdates = BURN_AU_PAUSE_ACTION_IFELEVATED; pEngineState->dwElevatedLoggingTlsId = TLS_OUT_OF_INDEXES; @@ -343,8 +344,10 @@ static HRESULT InitializeEngineState( ExitOnRootFailure(hr = E_INVALIDARG, "Missing required parameter for switch: %ls", BURN_COMMANDLINE_SWITCH_FILEHANDLE_ATTACHED); } - hr = StrStringToUInt32(wzParam, 0, reinterpret_cast(&hSourceEngineFile)); + hr = StrStringToUInt64(wzParam, 0, &qw); ExitOnFailure(hr, "Failed to parse file handle: '%ls'", (wzParam)); + + hSourceEngineFile = (HANDLE)qw; } if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, &pEngineState->argv[i][1], lstrlenW(BURN_COMMANDLINE_SWITCH_FILEHANDLE_SELF), BURN_COMMANDLINE_SWITCH_FILEHANDLE_SELF, lstrlenW(BURN_COMMANDLINE_SWITCH_FILEHANDLE_SELF))) { @@ -354,8 +357,10 @@ static HRESULT InitializeEngineState( ExitOnRootFailure(hr = E_INVALIDARG, "Missing required parameter for switch: %ls", BURN_COMMANDLINE_SWITCH_FILEHANDLE_SELF); } - hr = StrStringToUInt32(wzParam, 0, reinterpret_cast(&hSectionFile)); + hr = StrStringToUInt64(wzParam, 0, &qw); ExitOnFailure(hr, "Failed to parse file handle: '%ls'", (wzParam)); + + hSectionFile = (HANDLE)qw; } } } diff --git a/src/engine/engine.vcxproj b/src/engine/engine.vcxproj index a6deb18d..9e90ee19 100644 --- a/src/engine/engine.vcxproj +++ b/src/engine/engine.vcxproj @@ -1,7 +1,7 @@ - + Debug @@ -166,6 +166,6 @@ rc.exe -fo "$(OutDir)engine.res" "$(IntDir)engine.messages.rc" This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - + \ No newline at end of file diff --git a/src/engine/exeengine.cpp b/src/engine/exeengine.cpp index 0b53e266..8900984f 100644 --- a/src/engine/exeengine.cpp +++ b/src/engine/exeengine.cpp @@ -448,7 +448,7 @@ extern "C" HRESULT ExeEngineExecutePackage( } // build command - if (0 < lstrlenW(sczArguments)) + if (*sczArguments) { hr = VariableFormatString(pVariables, sczArguments, &sczArgumentsFormatted, NULL); ExitOnFailure(hr, "Failed to format argument string."); diff --git a/src/engine/logging.cpp b/src/engine/logging.cpp index fd2343fa..a1159c41 100644 --- a/src/engine/logging.cpp +++ b/src/engine/logging.cpp @@ -717,10 +717,10 @@ static HRESULT GetNonSessionSpecificTempFolder( { HRESULT hr = S_OK; WCHAR wzTempFolder[MAX_PATH] = { }; - DWORD cchTempFolder = 0; + SIZE_T cchTempFolder = 0; DWORD dwSessionId = 0; LPWSTR sczSessionId = 0; - DWORD cchSessionId = 0; + SIZE_T cchSessionId = 0; if (!::GetTempPathW(countof(wzTempFolder), wzTempFolder)) { @@ -740,7 +740,7 @@ static HRESULT GetNonSessionSpecificTempFolder( hr = ::StringCchLengthW(sczSessionId, STRSAFE_MAX_CCH, reinterpret_cast(&cchSessionId)); ExitOnFailure(hr, "Failed to get length of session id string."); - if (CSTR_EQUAL == ::CompareStringW(LOCALE_NEUTRAL, 0, wzTempFolder + cchTempFolder - cchSessionId, cchSessionId, sczSessionId, cchSessionId)) + if (CSTR_EQUAL == ::CompareStringW(LOCALE_NEUTRAL, 0, wzTempFolder + cchTempFolder - cchSessionId, static_cast(cchSessionId), sczSessionId, static_cast(cchSessionId))) { cchTempFolder -= cchSessionId; } diff --git a/src/engine/packages.config b/src/engine/packages.config index 125a949e..7219a3da 100644 --- a/src/engine/packages.config +++ b/src/engine/packages.config @@ -1,5 +1,5 @@  - + \ No newline at end of file diff --git a/src/engine/pipe.cpp b/src/engine/pipe.cpp index 47963e9d..a9fd24e8 100644 --- a/src/engine/pipe.cpp +++ b/src/engine/pipe.cpp @@ -429,7 +429,6 @@ extern "C" HRESULT PipeWaitForChildConnect( DWORD cbSecret = lstrlenW(wzSecret) * sizeof(WCHAR); DWORD dwCurrentProcessId = ::GetCurrentProcessId(); DWORD dwAck = 0; - DWORD cb = 0; for (DWORD i = 0; i < countof(hPipes) && INVALID_HANDLE_VALUE != hPipes[i]; ++i) { @@ -487,26 +486,18 @@ extern "C" HRESULT PipeWaitForChildConnect( } // Prove we are the one that created the elevated process by passing the secret. - if (!::WriteFile(hPipe, &cbSecret, sizeof(cbSecret), &cb, NULL)) - { - ExitWithLastError(hr, "Failed to write secret length to pipe."); - } + hr = FileWriteHandle(hPipe, reinterpret_cast(&cbSecret), sizeof(cbSecret)); + ExitOnFailure(hr, "Failed to write secret length to pipe."); - if (!::WriteFile(hPipe, wzSecret, cbSecret, &cb, NULL)) - { - ExitWithLastError(hr, "Failed to write secret to pipe."); - } + hr = FileWriteHandle(hPipe, reinterpret_cast(wzSecret), cbSecret); + ExitOnFailure(hr, "Failed to write secret to pipe."); - if (!::WriteFile(hPipe, &dwCurrentProcessId, sizeof(dwCurrentProcessId), &cb, NULL)) - { - ExitWithLastError(hr, "Failed to write our process id to pipe."); - } + hr = FileWriteHandle(hPipe, reinterpret_cast(&dwCurrentProcessId), sizeof(dwCurrentProcessId)); + ExitOnFailure(hr, "Failed to write our process id to pipe."); // Wait until the elevated process responds that it is ready to go. - if (!::ReadFile(hPipe, &dwAck, sizeof(dwAck), &cb, NULL)) - { - ExitWithLastError(hr, "Failed to read ACK from pipe."); - } + hr = FileReadHandle(hPipe, reinterpret_cast(&dwAck), sizeof(dwAck)); + ExitOnFailure(hr, "Failed to read ACK from pipe."); // The ACK should match out expected child process id. //if (pConnection->dwProcessId != dwAck) @@ -724,17 +715,8 @@ static HRESULT WritePipeMessage( ExitOnFailure(hr, "Failed to allocate message to write."); // Write the message. - DWORD cbWrote = 0; - SIZE_T cbTotalWritten = 0; - while (cbTotalWritten < cb) - { - if (!::WriteFile(hPipe, pv, (DWORD)(cb - cbTotalWritten), &cbWrote, NULL)) - { - ExitWithLastError(hr, "Failed to write message type to pipe."); - } - - cbTotalWritten += cbWrote; - } + hr = FileWriteHandle(hPipe, reinterpret_cast(pv), cb); + ExitOnFailure(hr, "Failed to write message type to pipe."); LExit: ReleaseMem(pv); @@ -747,46 +729,25 @@ static HRESULT GetPipeMessage( ) { HRESULT hr = S_OK; - DWORD rgdwMessageAndByteCount[2] = { }; - DWORD cb = 0; - DWORD cbRead = 0; + BYTE pbMessageAndByteCount[sizeof(DWORD) + sizeof(SIZE_T)] = { }; - while (cbRead < sizeof(rgdwMessageAndByteCount)) + hr = FileReadHandle(hPipe, pbMessageAndByteCount, sizeof(pbMessageAndByteCount)); + if (HRESULT_FROM_WIN32(ERROR_BROKEN_PIPE) == hr) { - if (!::ReadFile(hPipe, reinterpret_cast(rgdwMessageAndByteCount) + cbRead, sizeof(rgdwMessageAndByteCount) - cbRead, &cb, NULL)) - { - DWORD er = ::GetLastError(); - if (ERROR_MORE_DATA == er) - { - hr = S_OK; - } - else if (ERROR_BROKEN_PIPE == er) // parent process shut down, time to exit. - { - memset(rgdwMessageAndByteCount, 0, sizeof(rgdwMessageAndByteCount)); - hr = S_FALSE; - break; - } - else - { - hr = HRESULT_FROM_WIN32(er); - } - ExitOnRootFailure(hr, "Failed to read message from pipe."); - } - - cbRead += cb; + memset(pbMessageAndByteCount, 0, sizeof(pbMessageAndByteCount)); + hr = S_FALSE; } + ExitOnFailure(hr, "Failed to read message from pipe."); - pMsg->dwMessage = rgdwMessageAndByteCount[0]; - pMsg->cbData = rgdwMessageAndByteCount[1]; + pMsg->dwMessage = *(DWORD*)(pbMessageAndByteCount); + pMsg->cbData = *(SIZE_T*)(pbMessageAndByteCount + sizeof(DWORD)); if (pMsg->cbData) { pMsg->pvData = MemAlloc(pMsg->cbData, FALSE); ExitOnNull(pMsg->pvData, hr, E_OUTOFMEMORY, "Failed to allocate data for message."); - if (!::ReadFile(hPipe, pMsg->pvData, pMsg->cbData, &cb, NULL)) - { - ExitWithLastError(hr, "Failed to read data for message."); - } + hr = FileReadHandle(hPipe, reinterpret_cast(pMsg->pvData), pMsg->cbData); + ExitOnFailure(hr, "Failed to read data for message."); pMsg->fAllocatedData = TRUE; } @@ -810,15 +771,11 @@ static HRESULT ChildPipeConnected( LPWSTR sczVerificationSecret = NULL; DWORD cbVerificationSecret = 0; DWORD dwVerificationProcessId = 0; - DWORD dwRead = 0; DWORD dwAck = ::GetCurrentProcessId(); // send our process id as the ACK. - DWORD cb = 0; // Read the verification secret. - if (!::ReadFile(hPipe, &cbVerificationSecret, sizeof(cbVerificationSecret), &dwRead, NULL)) - { - ExitWithLastError(hr, "Failed to read size of verification secret from parent pipe."); - } + hr = FileReadHandle(hPipe, reinterpret_cast(&cbVerificationSecret), sizeof(cbVerificationSecret)); + ExitOnFailure(hr, "Failed to read size of verification secret from parent pipe."); if (255 < cbVerificationSecret / sizeof(WCHAR)) { @@ -829,10 +786,8 @@ static HRESULT ChildPipeConnected( hr = StrAlloc(&sczVerificationSecret, cbVerificationSecret / sizeof(WCHAR) + 1); ExitOnFailure(hr, "Failed to allocate buffer for verification secret."); - if (!::ReadFile(hPipe, sczVerificationSecret, cbVerificationSecret, &dwRead, NULL)) - { - ExitWithLastError(hr, "Failed to read verification secret from parent pipe."); - } + FileReadHandle(hPipe, reinterpret_cast(sczVerificationSecret), cbVerificationSecret); + ExitOnFailure(hr, "Failed to read verification secret from parent pipe."); // Verify the secrets match. if (CSTR_EQUAL != ::CompareStringW(LOCALE_NEUTRAL, 0, sczVerificationSecret, -1, wzSecret, -1)) @@ -842,10 +797,8 @@ static HRESULT ChildPipeConnected( } // Read the verification process id. - if (!::ReadFile(hPipe, &dwVerificationProcessId, sizeof(dwVerificationProcessId), &dwRead, NULL)) - { - ExitWithLastError(hr, "Failed to read verification process id from parent pipe."); - } + hr = FileReadHandle(hPipe, reinterpret_cast(&dwVerificationProcessId), sizeof(dwVerificationProcessId)); + ExitOnFailure(hr, "Failed to read verification process id from parent pipe."); // If a process id was not provided, we'll trust the process id from the parent. if (*pdwProcessId == 0) @@ -859,10 +812,8 @@ static HRESULT ChildPipeConnected( } // All is well, tell the parent process. - if (!::WriteFile(hPipe, &dwAck, sizeof(dwAck), &cb, NULL)) - { - ExitWithLastError(hr, "Failed to inform parent process that child is running."); - } + hr = FileWriteHandle(hPipe, reinterpret_cast(&dwAck), sizeof(dwAck)); + ExitOnFailure(hr, "Failed to inform parent process that child is running."); LExit: ReleaseStr(sczVerificationSecret); diff --git a/src/engine/pipe.h b/src/engine/pipe.h index 085c3a76..429cd824 100644 --- a/src/engine/pipe.h +++ b/src/engine/pipe.h @@ -27,7 +27,7 @@ typedef enum _BURN_PIPE_MESSAGE_TYPE : DWORD typedef struct _BURN_PIPE_MESSAGE { DWORD dwMessage; - DWORD cbData; + SIZE_T cbData; BOOL fAllocatedData; LPVOID pvData; diff --git a/src/engine/variable.cpp b/src/engine/variable.cpp index d0c67504..6f818ff3 100644 --- a/src/engine/variable.cpp +++ b/src/engine/variable.cpp @@ -1106,7 +1106,7 @@ static HRESULT FormatString( ::EnterCriticalSection(&pVariables->csAccess); // allocate buffer for format string - hr = ::StringCchLengthW(wzIn, STRSAFE_MAX_CCH - 1, &cchIn); + hr = ::StringCchLengthW(wzIn, STRSAFE_MAX_LENGTH, &cchIn); ExitOnFailure(hr, "Failed to length of format string."); hr = StrAlloc(&sczFormat, cchIn + 1); diff --git a/src/stub/packages.config b/src/stub/packages.config index 4f75128a..a98c0c8e 100644 --- a/src/stub/packages.config +++ b/src/stub/packages.config @@ -4,5 +4,5 @@ - + \ No newline at end of file diff --git a/src/stub/stub.vcxproj b/src/stub/stub.vcxproj index 2b8bd8ea..38710865 100644 --- a/src/stub/stub.vcxproj +++ b/src/stub/stub.vcxproj @@ -2,7 +2,7 @@ - + @@ -117,6 +117,6 @@ - + \ No newline at end of file diff --git a/src/test/BurnUnitTest/BurnUnitTest.vcxproj b/src/test/BurnUnitTest/BurnUnitTest.vcxproj index 11f96590..99db505d 100644 --- a/src/test/BurnUnitTest/BurnUnitTest.vcxproj +++ b/src/test/BurnUnitTest/BurnUnitTest.vcxproj @@ -3,8 +3,8 @@ - - + + Debug @@ -78,10 +78,10 @@ - ..\..\..\packages\WixBuildTools.TestSupport.4.0.47\lib\net472\WixBuildTools.TestSupport.dll + ..\..\..\packages\WixBuildTools.TestSupport.4.0.50\lib\net472\WixBuildTools.TestSupport.dll - ..\..\..\packages\WixBuildTools.TestSupport.Native.4.0.47\lib\net472\WixBuildTools.TestSupport.Native.dll + ..\..\..\packages\WixBuildTools.TestSupport.Native.4.0.50\lib\net472\WixBuildTools.TestSupport.Native.dll @@ -90,13 +90,13 @@ - + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - + + + \ No newline at end of file diff --git a/src/test/BurnUnitTest/packages.config b/src/test/BurnUnitTest/packages.config index 21d87cf8..1eb30932 100644 --- a/src/test/BurnUnitTest/packages.config +++ b/src/test/BurnUnitTest/packages.config @@ -1,9 +1,9 @@  - - - + + + -- cgit v1.2.3-55-g6feb