diff options
| author | Sean Hall <r.sean.hall@gmail.com> | 2022-03-30 17:05:56 -0500 |
|---|---|---|
| committer | Sean Hall <r.sean.hall@gmail.com> | 2022-04-01 22:06:11 -0500 |
| commit | ae3a31795614000207470e6824887c414366a681 (patch) | |
| tree | 7c3c659ee5efdbc7b4c7c93108221b229c26fd2d /src/burn/engine/bundlepackageengine.cpp | |
| parent | e7a208587389a17fa5ff3654d533e023268bfddf (diff) | |
| download | wix-ae3a31795614000207470e6824887c414366a681.tar.gz wix-ae3a31795614000207470e6824887c414366a681.tar.bz2 wix-ae3a31795614000207470e6824887c414366a681.zip | |
Minimize chance of user arguments messing up the command line
to avoid variations of issue 3890
Diffstat (limited to 'src/burn/engine/bundlepackageengine.cpp')
| -rw-r--r-- | src/burn/engine/bundlepackageengine.cpp | 71 |
1 files changed, 34 insertions, 37 deletions
diff --git a/src/burn/engine/bundlepackageengine.cpp b/src/burn/engine/bundlepackageengine.cpp index 0bee054f..89488b91 100644 --- a/src/burn/engine/bundlepackageengine.cpp +++ b/src/burn/engine/bundlepackageengine.cpp | |||
| @@ -252,12 +252,12 @@ extern "C" HRESULT BundlePackageEngineExecuteRelatedBundle( | |||
| 252 | { | 252 | { |
| 253 | HRESULT hr = S_OK; | 253 | HRESULT hr = S_OK; |
| 254 | LPCWSTR wzArguments = NULL; | 254 | LPCWSTR wzArguments = NULL; |
| 255 | LPWSTR sczArguments = NULL; | ||
| 256 | LPWSTR sczArgumentsFormatted = NULL; | ||
| 257 | LPWSTR sczArgumentsObfuscated = NULL; | ||
| 258 | LPWSTR sczCachedDirectory = NULL; | 255 | LPWSTR sczCachedDirectory = NULL; |
| 259 | LPWSTR sczExecutablePath = NULL; | 256 | LPWSTR sczExecutablePath = NULL; |
| 260 | LPWSTR sczCommand = NULL; | 257 | LPWSTR sczBaseCommand = NULL; |
| 258 | LPWSTR sczUnformattedUserArgs = NULL; | ||
| 259 | LPWSTR sczUserArgs = NULL; | ||
| 260 | LPWSTR sczUserArgsObfuscated = NULL; | ||
| 261 | LPWSTR sczCommandObfuscated = NULL; | 261 | LPWSTR sczCommandObfuscated = NULL; |
| 262 | HANDLE hExecutableFile = INVALID_HANDLE_VALUE; | 262 | HANDLE hExecutableFile = INVALID_HANDLE_VALUE; |
| 263 | STARTUPINFOW si = { }; | 263 | STARTUPINFOW si = { }; |
| @@ -309,7 +309,7 @@ extern "C" HRESULT BundlePackageEngineExecuteRelatedBundle( | |||
| 309 | // now add optional arguments | 309 | // now add optional arguments |
| 310 | if (wzArguments && *wzArguments) | 310 | if (wzArguments && *wzArguments) |
| 311 | { | 311 | { |
| 312 | hr = StrAllocString(&sczArguments, wzArguments, 0); | 312 | hr = StrAllocString(&sczUnformattedUserArgs, wzArguments, 0); |
| 313 | ExitOnFailure(hr, "Failed to copy package arguments."); | 313 | ExitOnFailure(hr, "Failed to copy package arguments."); |
| 314 | } | 314 | } |
| 315 | 315 | ||
| @@ -323,26 +323,26 @@ extern "C" HRESULT BundlePackageEngineExecuteRelatedBundle( | |||
| 323 | 323 | ||
| 324 | if (fCondition) | 324 | if (fCondition) |
| 325 | { | 325 | { |
| 326 | if (sczArguments) | 326 | if (sczUnformattedUserArgs) |
| 327 | { | 327 | { |
| 328 | hr = StrAllocConcat(&sczArguments, L" ", 0); | 328 | hr = StrAllocConcat(&sczUnformattedUserArgs, L" ", 0); |
| 329 | ExitOnFailure(hr, "Failed to separate command-line arguments."); | 329 | ExitOnFailure(hr, "Failed to separate command-line arguments."); |
| 330 | } | 330 | } |
| 331 | 331 | ||
| 332 | switch (action) | 332 | switch (action) |
| 333 | { | 333 | { |
| 334 | case BOOTSTRAPPER_ACTION_STATE_INSTALL: | 334 | case BOOTSTRAPPER_ACTION_STATE_INSTALL: |
| 335 | hr = StrAllocConcat(&sczArguments, commandLineArgument->sczInstallArgument, 0); | 335 | hr = StrAllocConcat(&sczUnformattedUserArgs, commandLineArgument->sczInstallArgument, 0); |
| 336 | ExitOnFailure(hr, "Failed to get command-line argument for install."); | 336 | ExitOnFailure(hr, "Failed to get command-line argument for install."); |
| 337 | break; | 337 | break; |
| 338 | 338 | ||
| 339 | case BOOTSTRAPPER_ACTION_STATE_UNINSTALL: | 339 | case BOOTSTRAPPER_ACTION_STATE_UNINSTALL: |
| 340 | hr = StrAllocConcat(&sczArguments, commandLineArgument->sczUninstallArgument, 0); | 340 | hr = StrAllocConcat(&sczUnformattedUserArgs, commandLineArgument->sczUninstallArgument, 0); |
| 341 | ExitOnFailure(hr, "Failed to get command-line argument for uninstall."); | 341 | ExitOnFailure(hr, "Failed to get command-line argument for uninstall."); |
| 342 | break; | 342 | break; |
| 343 | 343 | ||
| 344 | case BOOTSTRAPPER_ACTION_STATE_REPAIR: | 344 | case BOOTSTRAPPER_ACTION_STATE_REPAIR: |
| 345 | hr = StrAllocConcat(&sczArguments, commandLineArgument->sczRepairArgument, 0); | 345 | hr = StrAllocConcat(&sczUnformattedUserArgs, commandLineArgument->sczRepairArgument, 0); |
| 346 | ExitOnFailure(hr, "Failed to get command-line argument for repair."); | 346 | ExitOnFailure(hr, "Failed to get command-line argument for repair."); |
| 347 | break; | 347 | break; |
| 348 | 348 | ||
| @@ -353,75 +353,72 @@ extern "C" HRESULT BundlePackageEngineExecuteRelatedBundle( | |||
| 353 | } | 353 | } |
| 354 | } | 354 | } |
| 355 | 355 | ||
| 356 | // build command | 356 | // build base command |
| 357 | AppAppendCommandLineArgument(&sczCommand, sczExecutablePath); | 357 | hr = StrAllocFormatted(&sczBaseCommand, L"\"%ls\"", sczExecutablePath); |
| 358 | ExitOnFailure(hr, "Failed to create executable command."); | 358 | ExitOnFailure(hr, "Failed to allocate base command."); |
| 359 | 359 | ||
| 360 | if (!fRunEmbedded) | 360 | if (!fRunEmbedded) |
| 361 | { | 361 | { |
| 362 | hr = StrAllocConcat(&sczCommand, L" -quiet", 0); | 362 | hr = StrAllocConcat(&sczBaseCommand, L" -quiet", 0); |
| 363 | ExitOnFailure(hr, "Failed to append quiet argument."); | 363 | ExitOnFailure(hr, "Failed to append quiet argument."); |
| 364 | } | 364 | } |
| 365 | 365 | ||
| 366 | if (wzOperationCommandLine) | 366 | if (wzOperationCommandLine) |
| 367 | { | 367 | { |
| 368 | hr = StrAllocConcatFormatted(&sczCommand, L" %ls", wzOperationCommandLine); | 368 | hr = StrAllocConcatFormatted(&sczBaseCommand, L" %ls", wzOperationCommandLine); |
| 369 | ExitOnFailure(hr, "Failed to append operation argument."); | 369 | ExitOnFailure(hr, "Failed to append operation argument."); |
| 370 | } | 370 | } |
| 371 | 371 | ||
| 372 | if (wzRelationTypeCommandLine) | 372 | if (wzRelationTypeCommandLine) |
| 373 | { | 373 | { |
| 374 | hr = StrAllocConcatFormatted(&sczCommand, L" -%ls", wzRelationTypeCommandLine); | 374 | hr = StrAllocConcatFormatted(&sczBaseCommand, L" -%ls", wzRelationTypeCommandLine); |
| 375 | ExitOnFailure(hr, "Failed to append relation type argument."); | 375 | ExitOnFailure(hr, "Failed to append relation type argument."); |
| 376 | } | 376 | } |
| 377 | 377 | ||
| 378 | // Add the list of dependencies to ignore, if any, to the burn command line. | 378 | // Add the list of dependencies to ignore, if any, to the burn command line. |
| 379 | if (pExecuteAction->relatedBundle.sczIgnoreDependencies) | 379 | if (pExecuteAction->relatedBundle.sczIgnoreDependencies) |
| 380 | { | 380 | { |
| 381 | hr = StrAllocConcatFormatted(&sczCommand, L" -%ls=%ls", BURN_COMMANDLINE_SWITCH_IGNOREDEPENDENCIES, pExecuteAction->relatedBundle.sczIgnoreDependencies); | 381 | hr = StrAllocConcatFormatted(&sczBaseCommand, L" -%ls=%ls", BURN_COMMANDLINE_SWITCH_IGNOREDEPENDENCIES, pExecuteAction->relatedBundle.sczIgnoreDependencies); |
| 382 | ExitOnFailure(hr, "Failed to append the list of dependencies to ignore to the command line."); | 382 | ExitOnFailure(hr, "Failed to append the list of dependencies to ignore to the command line."); |
| 383 | } | 383 | } |
| 384 | 384 | ||
| 385 | // Add the list of ancestors, if any, to the burn command line. | 385 | // Add the list of ancestors, if any, to the burn command line. |
| 386 | if (pExecuteAction->relatedBundle.sczAncestors) | 386 | if (pExecuteAction->relatedBundle.sczAncestors) |
| 387 | { | 387 | { |
| 388 | hr = StrAllocConcatFormatted(&sczCommand, L" -%ls=%ls", BURN_COMMANDLINE_SWITCH_ANCESTORS, pExecuteAction->relatedBundle.sczAncestors); | 388 | hr = StrAllocConcatFormatted(&sczBaseCommand, L" -%ls=%ls", BURN_COMMANDLINE_SWITCH_ANCESTORS, pExecuteAction->relatedBundle.sczAncestors); |
| 389 | ExitOnFailure(hr, "Failed to append the list of ancestors to the command line."); | 389 | ExitOnFailure(hr, "Failed to append the list of ancestors to the command line."); |
| 390 | } | 390 | } |
| 391 | 391 | ||
| 392 | hr = CoreAppendEngineWorkingDirectoryToCommandLine(pExecuteAction->relatedBundle.sczEngineWorkingDirectory, &sczCommand, NULL); | 392 | hr = CoreAppendEngineWorkingDirectoryToCommandLine(pExecuteAction->relatedBundle.sczEngineWorkingDirectory, &sczBaseCommand, NULL); |
| 393 | ExitOnFailure(hr, "Failed to append the custom working directory to the bundlepackage command line."); | 393 | ExitOnFailure(hr, "Failed to append the custom working directory to the bundlepackage command line."); |
| 394 | 394 | ||
| 395 | hr = CoreAppendFileHandleSelfToCommandLine(sczExecutablePath, &hExecutableFile, &sczCommand, NULL); | 395 | hr = CoreAppendFileHandleSelfToCommandLine(sczExecutablePath, &hExecutableFile, &sczBaseCommand, NULL); |
| 396 | ExitOnFailure(hr, "Failed to append %ls", BURN_COMMANDLINE_SWITCH_FILEHANDLE_SELF); | 396 | ExitOnFailure(hr, "Failed to append %ls", BURN_COMMANDLINE_SWITCH_FILEHANDLE_SELF); |
| 397 | 397 | ||
| 398 | // Always add user supplied arguments last. | 398 | // build user args |
| 399 | if (sczArguments && *sczArguments) | 399 | if (sczUnformattedUserArgs && *sczUnformattedUserArgs) |
| 400 | { | 400 | { |
| 401 | hr = VariableFormatString(pVariables, sczArguments, &sczArgumentsFormatted, NULL); | 401 | hr = VariableFormatString(pVariables, sczUnformattedUserArgs, &sczUserArgs, NULL); |
| 402 | ExitOnFailure(hr, "Failed to format argument string."); | 402 | ExitOnFailure(hr, "Failed to format argument string."); |
| 403 | 403 | ||
| 404 | hr = VariableFormatStringObfuscated(pVariables, sczArguments, &sczArgumentsObfuscated, NULL); | 404 | hr = VariableFormatStringObfuscated(pVariables, sczUnformattedUserArgs, &sczUserArgsObfuscated, NULL); |
| 405 | ExitOnFailure(hr, "Failed to format obfuscated argument string."); | 405 | ExitOnFailure(hr, "Failed to format obfuscated argument string."); |
| 406 | 406 | ||
| 407 | hr = StrAllocFormatted(&sczCommandObfuscated, L"%ls %ls", sczCommand, sczArgumentsObfuscated); | 407 | hr = StrAllocFormatted(&sczCommandObfuscated, L"%ls %ls", sczBaseCommand, sczUserArgsObfuscated); |
| 408 | ExitOnFailure(hr, "Failed to copy obfuscated formatted arguments."); | 408 | ExitOnFailure(hr, "Failed to allocate obfuscated bundle command."); |
| 409 | |||
| 410 | hr = StrAllocConcatFormattedSecure(&sczCommand, L" %ls", sczArgumentsFormatted); | ||
| 411 | ExitOnFailure(hr, "Failed to copy formatted arguments."); | ||
| 412 | } | 409 | } |
| 413 | 410 | ||
| 414 | // Log before we add the secret pipe name and client token for embedded processes. | 411 | // Log obfuscated command, which won't include raw hidden variable values or protocol specific arguments to avoid exposing secrets. |
| 415 | LogId(REPORT_STANDARD, MSG_APPLYING_PACKAGE, LoggingRollbackOrExecute(fRollback), pPackage->sczId, LoggingActionStateToString(action), sczExecutablePath, sczCommandObfuscated); | 412 | LogId(REPORT_STANDARD, MSG_APPLYING_PACKAGE, LoggingRollbackOrExecute(fRollback), pPackage->sczId, LoggingActionStateToString(action), sczExecutablePath, sczCommandObfuscated ? sczCommandObfuscated : sczBaseCommand); |
| 416 | 413 | ||
| 417 | if (fRunEmbedded) | 414 | if (fRunEmbedded) |
| 418 | { | 415 | { |
| 419 | hr = EmbeddedRunBundle(sczExecutablePath, sczCommand, pfnGenericMessageHandler, pvContext, &dwExitCode); | 416 | hr = EmbeddedRunBundle(sczExecutablePath, sczBaseCommand, sczUserArgs, pfnGenericMessageHandler, pvContext, &dwExitCode); |
| 420 | ExitOnFailure(hr, "Failed to run bundle as embedded from path: %ls", sczExecutablePath); | 417 | ExitOnFailure(hr, "Failed to run bundle as embedded from path: %ls", sczExecutablePath); |
| 421 | } | 418 | } |
| 422 | else | 419 | else |
| 423 | { | 420 | { |
| 424 | hr = ExeEngineRunProcess(pfnGenericMessageHandler, pvContext, pPackage, sczExecutablePath, sczCommand, sczCachedDirectory, &dwExitCode); | 421 | hr = ExeEngineRunProcess(pfnGenericMessageHandler, pvContext, pPackage, sczExecutablePath, sczBaseCommand, sczUserArgs, sczCachedDirectory, &dwExitCode); |
| 425 | ExitOnFailure(hr, "Failed to run BUNDLE process"); | 422 | ExitOnFailure(hr, "Failed to run BUNDLE process"); |
| 426 | } | 423 | } |
| 427 | 424 | ||
| @@ -429,12 +426,12 @@ extern "C" HRESULT BundlePackageEngineExecuteRelatedBundle( | |||
| 429 | ExitOnRootFailure(hr, "Process returned error: 0x%x", dwExitCode); | 426 | ExitOnRootFailure(hr, "Process returned error: 0x%x", dwExitCode); |
| 430 | 427 | ||
| 431 | LExit: | 428 | LExit: |
| 432 | StrSecureZeroFreeString(sczArguments); | ||
| 433 | StrSecureZeroFreeString(sczArgumentsFormatted); | ||
| 434 | ReleaseStr(sczArgumentsObfuscated); | ||
| 435 | ReleaseStr(sczCachedDirectory); | 429 | ReleaseStr(sczCachedDirectory); |
| 436 | ReleaseStr(sczExecutablePath); | 430 | ReleaseStr(sczExecutablePath); |
| 437 | StrSecureZeroFreeString(sczCommand); | 431 | ReleaseStr(sczBaseCommand); |
| 432 | ReleaseStr(sczUnformattedUserArgs); | ||
| 433 | StrSecureZeroFreeString(sczUserArgs); | ||
| 434 | ReleaseStr(sczUserArgsObfuscated); | ||
| 438 | ReleaseStr(sczCommandObfuscated); | 435 | ReleaseStr(sczCommandObfuscated); |
| 439 | 436 | ||
| 440 | ReleaseHandle(pi.hThread); | 437 | ReleaseHandle(pi.hThread); |
