Make Burn ignore unknown embedded messages.
Sean Hall committed
Jun 29, 2022 at 10:29 UTC
67e32a09c7ea80ba76d4278bbac46f63489e2f5e
6 files changed
+58
-22
src/burn/engine/bundlepackageengine.cpp
+2
-5
@@ -763,8 +763,7 @@ static HRESULT ExecuteBundle(
763
LPWSTR* argvArp = NULL;
764
BOOL fRegistered = FALSE;
765
HANDLE hExecutableFile = INVALID_HANDLE_VALUE;
766
- STARTUPINFOW si = { };
767
- PROCESS_INFORMATION pi = { };
766
+ BURN_PIPE_CONNECTION connection = { };
767
DWORD dwExitCode = 0;
768
GENERIC_EXECUTE_MESSAGE message = { };
769
BURN_PAYLOAD* pPackagePayload = pPackage->payloads.rgItems[0].pPayload;
@@ -1006,7 +1005,7 @@ static HRESULT ExecuteBundle(
1005
1006
if (fRunEmbedded)
1007
{
1009
- hr = EmbeddedRunBundle(sczExecutablePath, sczBaseCommand, sczUserArgs, pfnGenericMessageHandler, pvContext, &dwExitCode);
1008
+ hr = EmbeddedRunBundle(&connection, sczExecutablePath, sczBaseCommand, sczUserArgs, pfnGenericMessageHandler, pvContext, &dwExitCode);
1009
ExitOnFailure(hr, "Failed to run bundle as embedded from path: %ls", sczExecutablePath);
1010
}
1011
else
@@ -1033,8 +1032,6 @@ LExit:
1032
AppFreeCommandLineArgs(argvArp);
1033
}
1034
1036
- ReleaseHandle(pi.hThread);
1037
- ReleaseHandle(pi.hProcess);
1035
ReleaseFileHandle(hExecutableFile);
1036
1037
// Best effort to clear the execute package cache folder and action variables.
src/burn/engine/embedded.cpp
+13
-13
@@ -40,6 +40,7 @@ static HRESULT OnEmbeddedProgress(
40
41
*******************************************************************/
42
extern "C" HRESULT EmbeddedRunBundle(
43
+ __in BURN_PIPE_CONNECTION* pConnection,
44
__in_z LPCWSTR wzExecutablePath,
45
__in_z LPWSTR sczBaseCommand,
46
__in_z_opt LPCWSTR wzUserArgs,
@@ -55,20 +56,19 @@ extern "C" HRESULT EmbeddedRunBundle(
56
PROCESS_INFORMATION pi = { };
57
BURN_PIPE_RESULT result = { };
58
58
- BURN_PIPE_CONNECTION connection = { };
59
- PipeConnectionInitialize(&connection);
59
+ PipeConnectionInitialize(pConnection);
60
61
BURN_EMBEDDED_CALLBACK_CONTEXT context = { };
62
context.pfnGenericMessageHandler = pfnGenericMessageHandler;
63
context.pvContext = pvContext;
64
65
- hr = PipeCreateNameAndSecret(&connection.sczName, &connection.sczSecret);
65
+ hr = PipeCreateNameAndSecret(&pConnection->sczName, &pConnection->sczSecret);
66
ExitOnFailure(hr, "Failed to create embedded pipe name and client token.");
67
68
- hr = PipeCreatePipes(&connection, FALSE, &hCreatedPipesEvent);
68
+ hr = PipeCreatePipes(pConnection, FALSE, &hCreatedPipesEvent);
69
ExitOnFailure(hr, "Failed to create embedded pipe.");
70
71
- hr = StrAllocFormatted(&sczCommand, L"%ls -%ls %ls %ls %u", sczBaseCommand, BURN_COMMANDLINE_SWITCH_EMBEDDED, connection.sczName, connection.sczSecret, dwCurrentProcessId);
71
+ hr = StrAllocFormatted(&sczCommand, L"%ls -%ls %ls %ls %u", sczBaseCommand, BURN_COMMANDLINE_SWITCH_EMBEDDED, pConnection->sczName, pConnection->sczSecret, dwCurrentProcessId);
72
ExitOnFailure(hr, "Failed to append embedded args.");
73
74
// Always add user supplied arguments last.
@@ -81,18 +81,18 @@ extern "C" HRESULT EmbeddedRunBundle(
81
hr = CoreCreateProcess(wzExecutablePath, sczCommand, TRUE, CREATE_NO_WINDOW, NULL, 0, &pi);
82
ExitOnFailure(hr, "Failed to create embedded process at path: %ls", wzExecutablePath);
83
84
- connection.dwProcessId = ::GetProcessId(pi.hProcess);
85
- connection.hProcess = pi.hProcess;
84
+ pConnection->dwProcessId = ::GetProcessId(pi.hProcess);
85
+ pConnection->hProcess = pi.hProcess;
86
pi.hProcess = NULL;
87
88
- hr = PipeWaitForChildConnect(&connection);
88
+ hr = PipeWaitForChildConnect(pConnection);
89
ExitOnFailure(hr, "Failed to wait for embedded process to connect to pipe.");
90
91
- hr = PipePumpMessages(connection.hPipe, ProcessEmbeddedMessages, &context, &result);
91
+ hr = PipePumpMessages(pConnection->hPipe, ProcessEmbeddedMessages, &context, &result);
92
ExitOnFailure(hr, "Failed to process messages from embedded message.");
93
94
// Get the return code from the embedded process.
95
- hr = CoreWaitForProcCompletion(connection.hProcess, INFINITE, pdwExitCode);
95
+ hr = CoreWaitForProcCompletion(pConnection->hProcess, INFINITE, pdwExitCode);
96
ExitOnFailure(hr, "Failed to wait for embedded executable: %ls", wzExecutablePath);
97
98
LExit:
@@ -101,7 +101,7 @@ LExit:
101
102
StrSecureZeroFreeString(sczCommand);
103
ReleaseHandle(hCreatedPipesEvent);
104
- PipeConnectionUninitialize(&connection);
104
+ PipeConnectionUninitialize(pConnection);
105
106
return hr;
107
}
@@ -133,8 +133,8 @@ static HRESULT ProcessEmbeddedMessages(
133
break;
134
135
default:
136
- hr = E_INVALIDARG;
137
- ExitOnRootFailure(hr, "Unexpected embedded message sent to child process, msg: %u", pMsg->dwMessage);
136
+ LogStringLine(REPORT_DEBUG, "Unexpected embedded message received from child process, msg: %u", pMsg->dwMessage);
137
+ dwResult = (DWORD)E_NOTIMPL;
138
}
139
140
*pdwResult = dwResult;
src/burn/engine/embedded.h
+1
@@ -15,6 +15,7 @@ typedef enum _BURN_EMBEDDED_MESSAGE_TYPE
15
16
17
HRESULT EmbeddedRunBundle(
18
+ __in BURN_PIPE_CONNECTION* pConnection,
19
__in_z LPCWSTR wzExecutablePath,
20
__in_z LPWSTR sczBaseCommand,
21
__in_z_opt LPCWSTR wzUserArgs,
src/burn/engine/exeengine.cpp
+2
-1
@@ -434,6 +434,7 @@ extern "C" HRESULT ExeEngineExecutePackage(
434
LPWSTR* argvArp = NULL;
435
BOOTSTRAPPER_PACKAGE_STATE applyState = BOOTSTRAPPER_PACKAGE_STATE_UNKNOWN;
436
HANDLE hExecutableFile = INVALID_HANDLE_VALUE;
437
+ BURN_PIPE_CONNECTION connection = { };
438
DWORD dwExitCode = 0;
439
BURN_PACKAGE* pPackage = pExecuteAction->exePackage.pPackage;
440
BURN_PAYLOAD* pPackagePayload = pPackage->payloads.rgItems[0].pPayload;
@@ -633,7 +634,7 @@ extern "C" HRESULT ExeEngineExecutePackage(
634
635
if (!pPackage->Exe.fFireAndForget && BURN_EXE_PROTOCOL_TYPE_BURN == pPackage->Exe.protocol)
636
{
636
- hr = EmbeddedRunBundle(sczExecutablePath, sczBaseCommand, sczUserArgs, pfnGenericMessageHandler, pvContext, &dwExitCode);
637
+ hr = EmbeddedRunBundle(&connection, sczExecutablePath, sczBaseCommand, sczUserArgs, pfnGenericMessageHandler, pvContext, &dwExitCode);
638
ExitOnFailure(hr, "Failed to run exe with Burn protocol from path: %ls", sczExecutablePath);
639
}
640
else if (!pPackage->Exe.fFireAndForget && BURN_EXE_PROTOCOL_TYPE_NETFX4 == pPackage->Exe.protocol)
src/burn/engine/externalengine.cpp
+18
-2
@@ -8,6 +8,11 @@ static HRESULT CopyStringToExternal(
8
__in_z_opt LPWSTR wzBuffer,
9
__inout SIZE_T* pcchBuffer
10
);
11
+static HRESULT ProcessUnknownEmbeddedMessages(
12
+ __in BURN_PIPE_MESSAGE* /*pMsg*/,
13
+ __in_opt LPVOID /*pvContext*/,
14
+ __out DWORD* pdwResult
15
+ );
16
17
// function definitions
18
@@ -212,7 +217,7 @@ HRESULT ExternalEngineSendEmbeddedError(
217
hr = BuffWriteNumber(&pbData, &cbData, dwUIHint);
218
ExitOnFailure(hr, "Failed to write UI hint to message buffer.");
219
215
- hr = PipeSendMessage(pEngineState->embeddedConnection.hPipe, BURN_EMBEDDED_MESSAGE_TYPE_ERROR, pbData, cbData, NULL, NULL, &dwResult);
220
+ hr = PipeSendMessage(pEngineState->embeddedConnection.hPipe, BURN_EMBEDDED_MESSAGE_TYPE_ERROR, pbData, cbData, ProcessUnknownEmbeddedMessages, NULL, &dwResult);
221
ExitOnFailure(hr, "Failed to send embedded message over pipe.");
222
223
*pnResult = static_cast<int>(dwResult);
@@ -247,7 +252,7 @@ HRESULT ExternalEngineSendEmbeddedProgress(
252
hr = BuffWriteNumber(&pbData, &cbData, dwOverallProgressPercentage);
253
ExitOnFailure(hr, "Failed to write overall progress percentage to message buffer.");
254
250
- hr = PipeSendMessage(pEngineState->embeddedConnection.hPipe, BURN_EMBEDDED_MESSAGE_TYPE_PROGRESS, pbData, cbData, NULL, NULL, &dwResult);
255
+ hr = PipeSendMessage(pEngineState->embeddedConnection.hPipe, BURN_EMBEDDED_MESSAGE_TYPE_PROGRESS, pbData, cbData, ProcessUnknownEmbeddedMessages, NULL, &dwResult);
256
ExitOnFailure(hr, "Failed to send embedded progress message over pipe.");
257
258
*pnResult = static_cast<int>(dwResult);
@@ -821,3 +826,14 @@ static HRESULT CopyStringToExternal(
826
827
return hr;
828
}
829
+
830
+static HRESULT ProcessUnknownEmbeddedMessages(
831
+ __in BURN_PIPE_MESSAGE* /*pMsg*/,
832
+ __in_opt LPVOID /*pvContext*/,
833
+ __out DWORD* pdwResult
834
+ )
835
+{
836
+ *pdwResult = (DWORD)E_NOTIMPL;
837
+
838
+ return S_OK;
839
+}
src/burn/test/BurnUnitTest/EmbeddedTest.cpp
+22
-1
@@ -3,12 +3,14 @@
3
#include "precomp.h"
4
5
6
+const DWORD TEST_UNKNOWN_MESSAGE_ID = 0xFFFE;
7
const HRESULT S_TEST_SUCCEEDED = 0x3133;
8
const DWORD TEST_EXIT_CODE = 666;
9
10
struct BUNDLE_RUNNER_CONTEXT
11
{
12
DWORD dwResult;
13
+ BURN_PIPE_CONNECTION connection;
14
};
15
16
@@ -68,7 +70,7 @@ namespace Bootstrapper
70
//
71
// bundle runner setup
72
//
71
- hr = EmbeddedRunBundle(L"C:\\ignored\\target.exe", L"\"C:\\ignored\\target.exe\"", NULL, EmbeddedTest_GenericMessageHandler, &bundleRunnerContext, &dwExitCode);
73
+ hr = EmbeddedRunBundle(&bundleRunnerContext.connection, L"C:\\ignored\\target.exe", L"\"C:\\ignored\\target.exe\"", NULL, EmbeddedTest_GenericMessageHandler, &bundleRunnerContext, &dwExitCode);
74
TestThrowOnFailure(hr, L"Failed to run embedded bundle.");
75
76
// check results
@@ -146,6 +148,15 @@ static DWORD CALLBACK EmbeddedTest_ThreadProc(
148
hr = PipeChildConnect(pConnection, FALSE);
149
ExitOnFailure(hr, "Failed to connect to parent bundle runner.");
150
151
+ // post unknown message
152
+ hr = PipeSendMessage(pConnection->hPipe, TEST_UNKNOWN_MESSAGE_ID, NULL, 0, NULL, NULL, &dwResult);
153
+ ExitOnFailure(hr, "Failed to post unknown message to parent bundle runner.");
154
+
155
+ if (E_NOTIMPL != dwResult)
156
+ {
157
+ ExitWithRootFailure(hr, E_UNEXPECTED, "Unexpected result from unknown message: %d", dwResult);
158
+ }
159
+
160
// post known message
161
hr = ExternalEngineSendEmbeddedError(&engineState, S_TEST_SUCCEEDED, NULL, 0, reinterpret_cast<int*>(&dwResult));
162
ExitOnFailure(hr, "Failed to post known message to parent bundle runner.");
@@ -167,9 +178,19 @@ static int EmbeddedTest_GenericMessageHandler(
178
179
if (GENERIC_EXECUTE_MESSAGE_ERROR == pMessage->type)
180
{
181
+ // post unknown message
182
+ HRESULT hr = PipeSendMessage(pContext->connection.hPipe, TEST_UNKNOWN_MESSAGE_ID, NULL, 0, NULL, NULL, &dwResult);
183
+ ExitOnFailure(hr, "Failed to post unknown message to embedded bundle.");
184
+
185
+ if (E_NOTIMPL != dwResult)
186
+ {
187
+ ExitWithRootFailure(hr, E_UNEXPECTED, "Unexpected result from unknown message: %d", dwResult);
188
+ }
189
+
190
pContext->dwResult = pMessage->error.dwErrorCode;
191
dwResult = TEST_EXIT_CODE;
192
}
193
194
+LExit:
195
return dwResult;
196
}