diff options
author | Sean Hall <r.sean.hall@gmail.com> | 2022-06-29 10:29:30 -0500 |
---|---|---|
committer | Sean Hall <r.sean.hall@gmail.com> | 2022-06-29 15:08:37 -0500 |
commit | 67e32a09c7ea80ba76d4278bbac46f63489e2f5e (patch) | |
tree | 269e7f91b778d28182a8c8bee159f5b2f0727b27 | |
parent | ec413164bd0285d1e9b9d36538974641a109b579 (diff) | |
download | wix-67e32a09c7ea80ba76d4278bbac46f63489e2f5e.tar.gz wix-67e32a09c7ea80ba76d4278bbac46f63489e2f5e.tar.bz2 wix-67e32a09c7ea80ba76d4278bbac46f63489e2f5e.zip |
Make Burn ignore unknown embedded messages.
-rw-r--r-- | src/burn/engine/bundlepackageengine.cpp | 7 | ||||
-rw-r--r-- | src/burn/engine/embedded.cpp | 26 | ||||
-rw-r--r-- | src/burn/engine/embedded.h | 1 | ||||
-rw-r--r-- | src/burn/engine/exeengine.cpp | 3 | ||||
-rw-r--r-- | src/burn/engine/externalengine.cpp | 20 | ||||
-rw-r--r-- | src/burn/test/BurnUnitTest/EmbeddedTest.cpp | 23 |
6 files changed, 58 insertions, 22 deletions
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( | |||
763 | LPWSTR* argvArp = NULL; | 763 | LPWSTR* argvArp = NULL; |
764 | BOOL fRegistered = FALSE; | 764 | BOOL fRegistered = FALSE; |
765 | HANDLE hExecutableFile = INVALID_HANDLE_VALUE; | 765 | HANDLE hExecutableFile = INVALID_HANDLE_VALUE; |
766 | STARTUPINFOW si = { }; | 766 | BURN_PIPE_CONNECTION connection = { }; |
767 | PROCESS_INFORMATION pi = { }; | ||
768 | DWORD dwExitCode = 0; | 767 | DWORD dwExitCode = 0; |
769 | GENERIC_EXECUTE_MESSAGE message = { }; | 768 | GENERIC_EXECUTE_MESSAGE message = { }; |
770 | BURN_PAYLOAD* pPackagePayload = pPackage->payloads.rgItems[0].pPayload; | 769 | BURN_PAYLOAD* pPackagePayload = pPackage->payloads.rgItems[0].pPayload; |
@@ -1006,7 +1005,7 @@ static HRESULT ExecuteBundle( | |||
1006 | 1005 | ||
1007 | if (fRunEmbedded) | 1006 | if (fRunEmbedded) |
1008 | { | 1007 | { |
1009 | hr = EmbeddedRunBundle(sczExecutablePath, sczBaseCommand, sczUserArgs, pfnGenericMessageHandler, pvContext, &dwExitCode); | 1008 | hr = EmbeddedRunBundle(&connection, sczExecutablePath, sczBaseCommand, sczUserArgs, pfnGenericMessageHandler, pvContext, &dwExitCode); |
1010 | ExitOnFailure(hr, "Failed to run bundle as embedded from path: %ls", sczExecutablePath); | 1009 | ExitOnFailure(hr, "Failed to run bundle as embedded from path: %ls", sczExecutablePath); |
1011 | } | 1010 | } |
1012 | else | 1011 | else |
@@ -1033,8 +1032,6 @@ LExit: | |||
1033 | AppFreeCommandLineArgs(argvArp); | 1032 | AppFreeCommandLineArgs(argvArp); |
1034 | } | 1033 | } |
1035 | 1034 | ||
1036 | ReleaseHandle(pi.hThread); | ||
1037 | ReleaseHandle(pi.hProcess); | ||
1038 | ReleaseFileHandle(hExecutableFile); | 1035 | ReleaseFileHandle(hExecutableFile); |
1039 | 1036 | ||
1040 | // Best effort to clear the execute package cache folder and action variables. | 1037 | // 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( | |||
40 | 40 | ||
41 | *******************************************************************/ | 41 | *******************************************************************/ |
42 | extern "C" HRESULT EmbeddedRunBundle( | 42 | extern "C" HRESULT EmbeddedRunBundle( |
43 | __in BURN_PIPE_CONNECTION* pConnection, | ||
43 | __in_z LPCWSTR wzExecutablePath, | 44 | __in_z LPCWSTR wzExecutablePath, |
44 | __in_z LPWSTR sczBaseCommand, | 45 | __in_z LPWSTR sczBaseCommand, |
45 | __in_z_opt LPCWSTR wzUserArgs, | 46 | __in_z_opt LPCWSTR wzUserArgs, |
@@ -55,20 +56,19 @@ extern "C" HRESULT EmbeddedRunBundle( | |||
55 | PROCESS_INFORMATION pi = { }; | 56 | PROCESS_INFORMATION pi = { }; |
56 | BURN_PIPE_RESULT result = { }; | 57 | BURN_PIPE_RESULT result = { }; |
57 | 58 | ||
58 | BURN_PIPE_CONNECTION connection = { }; | 59 | PipeConnectionInitialize(pConnection); |
59 | PipeConnectionInitialize(&connection); | ||
60 | 60 | ||
61 | BURN_EMBEDDED_CALLBACK_CONTEXT context = { }; | 61 | BURN_EMBEDDED_CALLBACK_CONTEXT context = { }; |
62 | context.pfnGenericMessageHandler = pfnGenericMessageHandler; | 62 | context.pfnGenericMessageHandler = pfnGenericMessageHandler; |
63 | context.pvContext = pvContext; | 63 | context.pvContext = pvContext; |
64 | 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."); | 66 | ExitOnFailure(hr, "Failed to create embedded pipe name and client token."); |
67 | 67 | ||
68 | hr = PipeCreatePipes(&connection, FALSE, &hCreatedPipesEvent); | 68 | hr = PipeCreatePipes(pConnection, FALSE, &hCreatedPipesEvent); |
69 | ExitOnFailure(hr, "Failed to create embedded pipe."); | 69 | ExitOnFailure(hr, "Failed to create embedded pipe."); |
70 | 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."); | 72 | ExitOnFailure(hr, "Failed to append embedded args."); |
73 | 73 | ||
74 | // Always add user supplied arguments last. | 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); | 81 | hr = CoreCreateProcess(wzExecutablePath, sczCommand, TRUE, CREATE_NO_WINDOW, NULL, 0, &pi); |
82 | ExitOnFailure(hr, "Failed to create embedded process at path: %ls", wzExecutablePath); | 82 | ExitOnFailure(hr, "Failed to create embedded process at path: %ls", wzExecutablePath); |
83 | 83 | ||
84 | connection.dwProcessId = ::GetProcessId(pi.hProcess); | 84 | pConnection->dwProcessId = ::GetProcessId(pi.hProcess); |
85 | connection.hProcess = pi.hProcess; | 85 | pConnection->hProcess = pi.hProcess; |
86 | pi.hProcess = NULL; | 86 | pi.hProcess = NULL; |
87 | 87 | ||
88 | hr = PipeWaitForChildConnect(&connection); | 88 | hr = PipeWaitForChildConnect(pConnection); |
89 | ExitOnFailure(hr, "Failed to wait for embedded process to connect to pipe."); | 89 | ExitOnFailure(hr, "Failed to wait for embedded process to connect to pipe."); |
90 | 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."); | 92 | ExitOnFailure(hr, "Failed to process messages from embedded message."); |
93 | 93 | ||
94 | // Get the return code from the embedded process. | 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); | 96 | ExitOnFailure(hr, "Failed to wait for embedded executable: %ls", wzExecutablePath); |
97 | 97 | ||
98 | LExit: | 98 | LExit: |
@@ -101,7 +101,7 @@ LExit: | |||
101 | 101 | ||
102 | StrSecureZeroFreeString(sczCommand); | 102 | StrSecureZeroFreeString(sczCommand); |
103 | ReleaseHandle(hCreatedPipesEvent); | 103 | ReleaseHandle(hCreatedPipesEvent); |
104 | PipeConnectionUninitialize(&connection); | 104 | PipeConnectionUninitialize(pConnection); |
105 | 105 | ||
106 | return hr; | 106 | return hr; |
107 | } | 107 | } |
@@ -133,8 +133,8 @@ static HRESULT ProcessEmbeddedMessages( | |||
133 | break; | 133 | break; |
134 | 134 | ||
135 | default: | 135 | default: |
136 | hr = E_INVALIDARG; | 136 | LogStringLine(REPORT_DEBUG, "Unexpected embedded message received from child process, msg: %u", pMsg->dwMessage); |
137 | ExitOnRootFailure(hr, "Unexpected embedded message sent to child process, msg: %u", pMsg->dwMessage); | 137 | dwResult = (DWORD)E_NOTIMPL; |
138 | } | 138 | } |
139 | 139 | ||
140 | *pdwResult = dwResult; | 140 | *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 | |||
15 | 15 | ||
16 | 16 | ||
17 | HRESULT EmbeddedRunBundle( | 17 | HRESULT EmbeddedRunBundle( |
18 | __in BURN_PIPE_CONNECTION* pConnection, | ||
18 | __in_z LPCWSTR wzExecutablePath, | 19 | __in_z LPCWSTR wzExecutablePath, |
19 | __in_z LPWSTR sczBaseCommand, | 20 | __in_z LPWSTR sczBaseCommand, |
20 | __in_z_opt LPCWSTR wzUserArgs, | 21 | __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( | |||
434 | LPWSTR* argvArp = NULL; | 434 | LPWSTR* argvArp = NULL; |
435 | BOOTSTRAPPER_PACKAGE_STATE applyState = BOOTSTRAPPER_PACKAGE_STATE_UNKNOWN; | 435 | BOOTSTRAPPER_PACKAGE_STATE applyState = BOOTSTRAPPER_PACKAGE_STATE_UNKNOWN; |
436 | HANDLE hExecutableFile = INVALID_HANDLE_VALUE; | 436 | HANDLE hExecutableFile = INVALID_HANDLE_VALUE; |
437 | BURN_PIPE_CONNECTION connection = { }; | ||
437 | DWORD dwExitCode = 0; | 438 | DWORD dwExitCode = 0; |
438 | BURN_PACKAGE* pPackage = pExecuteAction->exePackage.pPackage; | 439 | BURN_PACKAGE* pPackage = pExecuteAction->exePackage.pPackage; |
439 | BURN_PAYLOAD* pPackagePayload = pPackage->payloads.rgItems[0].pPayload; | 440 | BURN_PAYLOAD* pPackagePayload = pPackage->payloads.rgItems[0].pPayload; |
@@ -633,7 +634,7 @@ extern "C" HRESULT ExeEngineExecutePackage( | |||
633 | 634 | ||
634 | if (!pPackage->Exe.fFireAndForget && BURN_EXE_PROTOCOL_TYPE_BURN == pPackage->Exe.protocol) | 635 | if (!pPackage->Exe.fFireAndForget && BURN_EXE_PROTOCOL_TYPE_BURN == pPackage->Exe.protocol) |
635 | { | 636 | { |
636 | hr = EmbeddedRunBundle(sczExecutablePath, sczBaseCommand, sczUserArgs, pfnGenericMessageHandler, pvContext, &dwExitCode); | 637 | hr = EmbeddedRunBundle(&connection, sczExecutablePath, sczBaseCommand, sczUserArgs, pfnGenericMessageHandler, pvContext, &dwExitCode); |
637 | ExitOnFailure(hr, "Failed to run exe with Burn protocol from path: %ls", sczExecutablePath); | 638 | ExitOnFailure(hr, "Failed to run exe with Burn protocol from path: %ls", sczExecutablePath); |
638 | } | 639 | } |
639 | else if (!pPackage->Exe.fFireAndForget && BURN_EXE_PROTOCOL_TYPE_NETFX4 == pPackage->Exe.protocol) | 640 | 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( | |||
8 | __in_z_opt LPWSTR wzBuffer, | 8 | __in_z_opt LPWSTR wzBuffer, |
9 | __inout SIZE_T* pcchBuffer | 9 | __inout SIZE_T* pcchBuffer |
10 | ); | 10 | ); |
11 | static HRESULT ProcessUnknownEmbeddedMessages( | ||
12 | __in BURN_PIPE_MESSAGE* /*pMsg*/, | ||
13 | __in_opt LPVOID /*pvContext*/, | ||
14 | __out DWORD* pdwResult | ||
15 | ); | ||
11 | 16 | ||
12 | // function definitions | 17 | // function definitions |
13 | 18 | ||
@@ -212,7 +217,7 @@ HRESULT ExternalEngineSendEmbeddedError( | |||
212 | hr = BuffWriteNumber(&pbData, &cbData, dwUIHint); | 217 | hr = BuffWriteNumber(&pbData, &cbData, dwUIHint); |
213 | ExitOnFailure(hr, "Failed to write UI hint to message buffer."); | 218 | ExitOnFailure(hr, "Failed to write UI hint to message buffer."); |
214 | 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); |
216 | ExitOnFailure(hr, "Failed to send embedded message over pipe."); | 221 | ExitOnFailure(hr, "Failed to send embedded message over pipe."); |
217 | 222 | ||
218 | *pnResult = static_cast<int>(dwResult); | 223 | *pnResult = static_cast<int>(dwResult); |
@@ -247,7 +252,7 @@ HRESULT ExternalEngineSendEmbeddedProgress( | |||
247 | hr = BuffWriteNumber(&pbData, &cbData, dwOverallProgressPercentage); | 252 | hr = BuffWriteNumber(&pbData, &cbData, dwOverallProgressPercentage); |
248 | ExitOnFailure(hr, "Failed to write overall progress percentage to message buffer."); | 253 | ExitOnFailure(hr, "Failed to write overall progress percentage to message buffer."); |
249 | 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); |
251 | ExitOnFailure(hr, "Failed to send embedded progress message over pipe."); | 256 | ExitOnFailure(hr, "Failed to send embedded progress message over pipe."); |
252 | 257 | ||
253 | *pnResult = static_cast<int>(dwResult); | 258 | *pnResult = static_cast<int>(dwResult); |
@@ -821,3 +826,14 @@ static HRESULT CopyStringToExternal( | |||
821 | 826 | ||
822 | return hr; | 827 | return hr; |
823 | } | 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 | } | ||
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 @@ | |||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | 5 | ||
6 | const DWORD TEST_UNKNOWN_MESSAGE_ID = 0xFFFE; | ||
6 | const HRESULT S_TEST_SUCCEEDED = 0x3133; | 7 | const HRESULT S_TEST_SUCCEEDED = 0x3133; |
7 | const DWORD TEST_EXIT_CODE = 666; | 8 | const DWORD TEST_EXIT_CODE = 666; |
8 | 9 | ||
9 | struct BUNDLE_RUNNER_CONTEXT | 10 | struct BUNDLE_RUNNER_CONTEXT |
10 | { | 11 | { |
11 | DWORD dwResult; | 12 | DWORD dwResult; |
13 | BURN_PIPE_CONNECTION connection; | ||
12 | }; | 14 | }; |
13 | 15 | ||
14 | 16 | ||
@@ -68,7 +70,7 @@ namespace Bootstrapper | |||
68 | // | 70 | // |
69 | // bundle runner setup | 71 | // bundle runner setup |
70 | // | 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); |
72 | TestThrowOnFailure(hr, L"Failed to run embedded bundle."); | 74 | TestThrowOnFailure(hr, L"Failed to run embedded bundle."); |
73 | 75 | ||
74 | // check results | 76 | // check results |
@@ -146,6 +148,15 @@ static DWORD CALLBACK EmbeddedTest_ThreadProc( | |||
146 | hr = PipeChildConnect(pConnection, FALSE); | 148 | hr = PipeChildConnect(pConnection, FALSE); |
147 | ExitOnFailure(hr, "Failed to connect to parent bundle runner."); | 149 | ExitOnFailure(hr, "Failed to connect to parent bundle runner."); |
148 | 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 | |||
149 | // post known message | 160 | // post known message |
150 | hr = ExternalEngineSendEmbeddedError(&engineState, S_TEST_SUCCEEDED, NULL, 0, reinterpret_cast<int*>(&dwResult)); | 161 | hr = ExternalEngineSendEmbeddedError(&engineState, S_TEST_SUCCEEDED, NULL, 0, reinterpret_cast<int*>(&dwResult)); |
151 | ExitOnFailure(hr, "Failed to post known message to parent bundle runner."); | 162 | ExitOnFailure(hr, "Failed to post known message to parent bundle runner."); |
@@ -167,9 +178,19 @@ static int EmbeddedTest_GenericMessageHandler( | |||
167 | 178 | ||
168 | if (GENERIC_EXECUTE_MESSAGE_ERROR == pMessage->type) | 179 | if (GENERIC_EXECUTE_MESSAGE_ERROR == pMessage->type) |
169 | { | 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 | |||
170 | pContext->dwResult = pMessage->error.dwErrorCode; | 190 | pContext->dwResult = pMessage->error.dwErrorCode; |
171 | dwResult = TEST_EXIT_CODE; | 191 | dwResult = TEST_EXIT_CODE; |
172 | } | 192 | } |
173 | 193 | ||
194 | LExit: | ||
174 | return dwResult; | 195 | return dwResult; |
175 | } | 196 | } |