From 67e32a09c7ea80ba76d4278bbac46f63489e2f5e Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Wed, 29 Jun 2022 10:29:30 -0500 Subject: Make Burn ignore unknown embedded messages. --- src/burn/engine/bundlepackageengine.cpp | 7 ++----- src/burn/engine/embedded.cpp | 26 +++++++++++++------------- src/burn/engine/embedded.h | 1 + src/burn/engine/exeengine.cpp | 3 ++- src/burn/engine/externalengine.cpp | 20 ++++++++++++++++++-- src/burn/test/BurnUnitTest/EmbeddedTest.cpp | 23 ++++++++++++++++++++++- 6 files changed, 58 insertions(+), 22 deletions(-) (limited to 'src/burn') diff --git a/src/burn/engine/bundlepackageengine.cpp b/src/burn/engine/bundlepackageengine.cpp index 7ae12a1e..dafe1967 100644 --- a/src/burn/engine/bundlepackageengine.cpp +++ b/src/burn/engine/bundlepackageengine.cpp @@ -763,8 +763,7 @@ static HRESULT ExecuteBundle( LPWSTR* argvArp = NULL; BOOL fRegistered = FALSE; HANDLE hExecutableFile = INVALID_HANDLE_VALUE; - STARTUPINFOW si = { }; - PROCESS_INFORMATION pi = { }; + BURN_PIPE_CONNECTION connection = { }; DWORD dwExitCode = 0; GENERIC_EXECUTE_MESSAGE message = { }; BURN_PAYLOAD* pPackagePayload = pPackage->payloads.rgItems[0].pPayload; @@ -1006,7 +1005,7 @@ static HRESULT ExecuteBundle( if (fRunEmbedded) { - hr = EmbeddedRunBundle(sczExecutablePath, sczBaseCommand, sczUserArgs, pfnGenericMessageHandler, pvContext, &dwExitCode); + hr = EmbeddedRunBundle(&connection, sczExecutablePath, sczBaseCommand, sczUserArgs, pfnGenericMessageHandler, pvContext, &dwExitCode); ExitOnFailure(hr, "Failed to run bundle as embedded from path: %ls", sczExecutablePath); } else @@ -1033,8 +1032,6 @@ LExit: AppFreeCommandLineArgs(argvArp); } - ReleaseHandle(pi.hThread); - ReleaseHandle(pi.hProcess); ReleaseFileHandle(hExecutableFile); // Best effort to clear the execute package cache folder and action variables. diff --git a/src/burn/engine/embedded.cpp b/src/burn/engine/embedded.cpp index 4c3de98e..ac4c76d0 100644 --- a/src/burn/engine/embedded.cpp +++ b/src/burn/engine/embedded.cpp @@ -40,6 +40,7 @@ static HRESULT OnEmbeddedProgress( *******************************************************************/ extern "C" HRESULT EmbeddedRunBundle( + __in BURN_PIPE_CONNECTION* pConnection, __in_z LPCWSTR wzExecutablePath, __in_z LPWSTR sczBaseCommand, __in_z_opt LPCWSTR wzUserArgs, @@ -55,20 +56,19 @@ extern "C" HRESULT EmbeddedRunBundle( PROCESS_INFORMATION pi = { }; BURN_PIPE_RESULT result = { }; - BURN_PIPE_CONNECTION connection = { }; - PipeConnectionInitialize(&connection); + PipeConnectionInitialize(pConnection); BURN_EMBEDDED_CALLBACK_CONTEXT context = { }; context.pfnGenericMessageHandler = pfnGenericMessageHandler; context.pvContext = pvContext; - hr = PipeCreateNameAndSecret(&connection.sczName, &connection.sczSecret); + hr = PipeCreateNameAndSecret(&pConnection->sczName, &pConnection->sczSecret); ExitOnFailure(hr, "Failed to create embedded pipe name and client token."); - hr = PipeCreatePipes(&connection, FALSE, &hCreatedPipesEvent); + hr = PipeCreatePipes(pConnection, FALSE, &hCreatedPipesEvent); ExitOnFailure(hr, "Failed to create embedded pipe."); - hr = StrAllocFormatted(&sczCommand, L"%ls -%ls %ls %ls %u", sczBaseCommand, BURN_COMMANDLINE_SWITCH_EMBEDDED, connection.sczName, connection.sczSecret, dwCurrentProcessId); + hr = StrAllocFormatted(&sczCommand, L"%ls -%ls %ls %ls %u", sczBaseCommand, BURN_COMMANDLINE_SWITCH_EMBEDDED, pConnection->sczName, pConnection->sczSecret, dwCurrentProcessId); ExitOnFailure(hr, "Failed to append embedded args."); // Always add user supplied arguments last. @@ -81,18 +81,18 @@ extern "C" HRESULT EmbeddedRunBundle( hr = CoreCreateProcess(wzExecutablePath, sczCommand, TRUE, CREATE_NO_WINDOW, NULL, 0, &pi); ExitOnFailure(hr, "Failed to create embedded process at path: %ls", wzExecutablePath); - connection.dwProcessId = ::GetProcessId(pi.hProcess); - connection.hProcess = pi.hProcess; + pConnection->dwProcessId = ::GetProcessId(pi.hProcess); + pConnection->hProcess = pi.hProcess; pi.hProcess = NULL; - hr = PipeWaitForChildConnect(&connection); + hr = PipeWaitForChildConnect(pConnection); ExitOnFailure(hr, "Failed to wait for embedded process to connect to pipe."); - hr = PipePumpMessages(connection.hPipe, ProcessEmbeddedMessages, &context, &result); + hr = PipePumpMessages(pConnection->hPipe, ProcessEmbeddedMessages, &context, &result); ExitOnFailure(hr, "Failed to process messages from embedded message."); // Get the return code from the embedded process. - hr = CoreWaitForProcCompletion(connection.hProcess, INFINITE, pdwExitCode); + hr = CoreWaitForProcCompletion(pConnection->hProcess, INFINITE, pdwExitCode); ExitOnFailure(hr, "Failed to wait for embedded executable: %ls", wzExecutablePath); LExit: @@ -101,7 +101,7 @@ LExit: StrSecureZeroFreeString(sczCommand); ReleaseHandle(hCreatedPipesEvent); - PipeConnectionUninitialize(&connection); + PipeConnectionUninitialize(pConnection); return hr; } @@ -133,8 +133,8 @@ static HRESULT ProcessEmbeddedMessages( break; default: - hr = E_INVALIDARG; - ExitOnRootFailure(hr, "Unexpected embedded message sent to child process, msg: %u", pMsg->dwMessage); + LogStringLine(REPORT_DEBUG, "Unexpected embedded message received from child process, msg: %u", pMsg->dwMessage); + dwResult = (DWORD)E_NOTIMPL; } *pdwResult = dwResult; diff --git a/src/burn/engine/embedded.h b/src/burn/engine/embedded.h index 905b227f..0a0a8fc2 100644 --- a/src/burn/engine/embedded.h +++ b/src/burn/engine/embedded.h @@ -15,6 +15,7 @@ typedef enum _BURN_EMBEDDED_MESSAGE_TYPE HRESULT EmbeddedRunBundle( + __in BURN_PIPE_CONNECTION* pConnection, __in_z LPCWSTR wzExecutablePath, __in_z LPWSTR sczBaseCommand, __in_z_opt LPCWSTR wzUserArgs, diff --git a/src/burn/engine/exeengine.cpp b/src/burn/engine/exeengine.cpp index 1168f5ea..ef0015ac 100644 --- a/src/burn/engine/exeengine.cpp +++ b/src/burn/engine/exeengine.cpp @@ -434,6 +434,7 @@ extern "C" HRESULT ExeEngineExecutePackage( LPWSTR* argvArp = NULL; BOOTSTRAPPER_PACKAGE_STATE applyState = BOOTSTRAPPER_PACKAGE_STATE_UNKNOWN; HANDLE hExecutableFile = INVALID_HANDLE_VALUE; + BURN_PIPE_CONNECTION connection = { }; DWORD dwExitCode = 0; BURN_PACKAGE* pPackage = pExecuteAction->exePackage.pPackage; BURN_PAYLOAD* pPackagePayload = pPackage->payloads.rgItems[0].pPayload; @@ -633,7 +634,7 @@ extern "C" HRESULT ExeEngineExecutePackage( if (!pPackage->Exe.fFireAndForget && BURN_EXE_PROTOCOL_TYPE_BURN == pPackage->Exe.protocol) { - hr = EmbeddedRunBundle(sczExecutablePath, sczBaseCommand, sczUserArgs, pfnGenericMessageHandler, pvContext, &dwExitCode); + hr = EmbeddedRunBundle(&connection, sczExecutablePath, sczBaseCommand, sczUserArgs, pfnGenericMessageHandler, pvContext, &dwExitCode); ExitOnFailure(hr, "Failed to run exe with Burn protocol from path: %ls", sczExecutablePath); } else if (!pPackage->Exe.fFireAndForget && BURN_EXE_PROTOCOL_TYPE_NETFX4 == pPackage->Exe.protocol) diff --git a/src/burn/engine/externalengine.cpp b/src/burn/engine/externalengine.cpp index abe9b8bc..16977395 100644 --- a/src/burn/engine/externalengine.cpp +++ b/src/burn/engine/externalengine.cpp @@ -8,6 +8,11 @@ static HRESULT CopyStringToExternal( __in_z_opt LPWSTR wzBuffer, __inout SIZE_T* pcchBuffer ); +static HRESULT ProcessUnknownEmbeddedMessages( + __in BURN_PIPE_MESSAGE* /*pMsg*/, + __in_opt LPVOID /*pvContext*/, + __out DWORD* pdwResult + ); // function definitions @@ -212,7 +217,7 @@ HRESULT ExternalEngineSendEmbeddedError( hr = BuffWriteNumber(&pbData, &cbData, dwUIHint); ExitOnFailure(hr, "Failed to write UI hint to message buffer."); - hr = PipeSendMessage(pEngineState->embeddedConnection.hPipe, BURN_EMBEDDED_MESSAGE_TYPE_ERROR, pbData, cbData, NULL, NULL, &dwResult); + hr = PipeSendMessage(pEngineState->embeddedConnection.hPipe, BURN_EMBEDDED_MESSAGE_TYPE_ERROR, pbData, cbData, ProcessUnknownEmbeddedMessages, NULL, &dwResult); ExitOnFailure(hr, "Failed to send embedded message over pipe."); *pnResult = static_cast(dwResult); @@ -247,7 +252,7 @@ HRESULT ExternalEngineSendEmbeddedProgress( hr = BuffWriteNumber(&pbData, &cbData, dwOverallProgressPercentage); ExitOnFailure(hr, "Failed to write overall progress percentage to message buffer."); - hr = PipeSendMessage(pEngineState->embeddedConnection.hPipe, BURN_EMBEDDED_MESSAGE_TYPE_PROGRESS, pbData, cbData, NULL, NULL, &dwResult); + hr = PipeSendMessage(pEngineState->embeddedConnection.hPipe, BURN_EMBEDDED_MESSAGE_TYPE_PROGRESS, pbData, cbData, ProcessUnknownEmbeddedMessages, NULL, &dwResult); ExitOnFailure(hr, "Failed to send embedded progress message over pipe."); *pnResult = static_cast(dwResult); @@ -821,3 +826,14 @@ static HRESULT CopyStringToExternal( return hr; } + +static HRESULT ProcessUnknownEmbeddedMessages( + __in BURN_PIPE_MESSAGE* /*pMsg*/, + __in_opt LPVOID /*pvContext*/, + __out DWORD* pdwResult + ) +{ + *pdwResult = (DWORD)E_NOTIMPL; + + return S_OK; +} diff --git a/src/burn/test/BurnUnitTest/EmbeddedTest.cpp b/src/burn/test/BurnUnitTest/EmbeddedTest.cpp index cac1ba81..7560fe25 100644 --- a/src/burn/test/BurnUnitTest/EmbeddedTest.cpp +++ b/src/burn/test/BurnUnitTest/EmbeddedTest.cpp @@ -3,12 +3,14 @@ #include "precomp.h" +const DWORD TEST_UNKNOWN_MESSAGE_ID = 0xFFFE; const HRESULT S_TEST_SUCCEEDED = 0x3133; const DWORD TEST_EXIT_CODE = 666; struct BUNDLE_RUNNER_CONTEXT { DWORD dwResult; + BURN_PIPE_CONNECTION connection; }; @@ -68,7 +70,7 @@ namespace Bootstrapper // // bundle runner setup // - hr = EmbeddedRunBundle(L"C:\\ignored\\target.exe", L"\"C:\\ignored\\target.exe\"", NULL, EmbeddedTest_GenericMessageHandler, &bundleRunnerContext, &dwExitCode); + hr = EmbeddedRunBundle(&bundleRunnerContext.connection, L"C:\\ignored\\target.exe", L"\"C:\\ignored\\target.exe\"", NULL, EmbeddedTest_GenericMessageHandler, &bundleRunnerContext, &dwExitCode); TestThrowOnFailure(hr, L"Failed to run embedded bundle."); // check results @@ -146,6 +148,15 @@ static DWORD CALLBACK EmbeddedTest_ThreadProc( hr = PipeChildConnect(pConnection, FALSE); ExitOnFailure(hr, "Failed to connect to parent bundle runner."); + // post unknown message + hr = PipeSendMessage(pConnection->hPipe, TEST_UNKNOWN_MESSAGE_ID, NULL, 0, NULL, NULL, &dwResult); + ExitOnFailure(hr, "Failed to post unknown message to parent bundle runner."); + + if (E_NOTIMPL != dwResult) + { + ExitWithRootFailure(hr, E_UNEXPECTED, "Unexpected result from unknown message: %d", dwResult); + } + // post known message hr = ExternalEngineSendEmbeddedError(&engineState, S_TEST_SUCCEEDED, NULL, 0, reinterpret_cast(&dwResult)); ExitOnFailure(hr, "Failed to post known message to parent bundle runner."); @@ -167,9 +178,19 @@ static int EmbeddedTest_GenericMessageHandler( if (GENERIC_EXECUTE_MESSAGE_ERROR == pMessage->type) { + // post unknown message + HRESULT hr = PipeSendMessage(pContext->connection.hPipe, TEST_UNKNOWN_MESSAGE_ID, NULL, 0, NULL, NULL, &dwResult); + ExitOnFailure(hr, "Failed to post unknown message to embedded bundle."); + + if (E_NOTIMPL != dwResult) + { + ExitWithRootFailure(hr, E_UNEXPECTED, "Unexpected result from unknown message: %d", dwResult); + } + pContext->dwResult = pMessage->error.dwErrorCode; dwResult = TEST_EXIT_CODE; } +LExit: return dwResult; } -- cgit v1.2.3-55-g6feb