From 68ec803fc7f48bb0e0463dc45f6ce40e1f07dbf5 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Fri, 3 Jun 2022 17:50:50 -0500 Subject: Make sure base paths are fully qualified in Burn. --- src/burn/engine/apply.cpp | 2 +- src/burn/engine/bundlepackageengine.cpp | 2 +- src/burn/engine/cache.cpp | 56 ++++++++++++++------------ src/burn/engine/core.cpp | 2 +- src/burn/engine/engine.mc | 7 ++++ src/burn/engine/exeengine.cpp | 2 +- src/burn/engine/msiengine.cpp | 4 +- src/burn/engine/mspengine.cpp | 2 +- src/burn/engine/msuengine.cpp | 2 +- src/burn/engine/payload.cpp | 2 +- src/burn/engine/plan.cpp | 11 +++-- src/burn/engine/registration.cpp | 6 +-- src/libs/dutil/WixToolset.DUtil/inc/pathutil.h | 10 +++++ src/libs/dutil/WixToolset.DUtil/path2utl.cpp | 19 +++++++++ 14 files changed, 87 insertions(+), 40 deletions(-) (limited to 'src') diff --git a/src/burn/engine/apply.cpp b/src/burn/engine/apply.cpp index 4ebed191..048cd98b 100644 --- a/src/burn/engine/apply.cpp +++ b/src/burn/engine/apply.cpp @@ -1371,7 +1371,7 @@ static HRESULT LayoutBundle( ExitOnFailure(hr, "Failed to get path to bundle to layout."); } - hr = PathConcatRelativeToBase(pContext->wzLayoutDirectory, wzExecutableName, &sczDestinationPath); + hr = PathConcatRelativeToFullyQualifiedBase(pContext->wzLayoutDirectory, wzExecutableName, &sczDestinationPath); ExitOnFailure(hr, "Failed to concat layout path for bundle."); // If the destination path is the currently running bundle, bail. diff --git a/src/burn/engine/bundlepackageengine.cpp b/src/burn/engine/bundlepackageengine.cpp index 8ba8e0d2..6a0343bd 100644 --- a/src/burn/engine/bundlepackageengine.cpp +++ b/src/burn/engine/bundlepackageengine.cpp @@ -780,7 +780,7 @@ static HRESULT ExecuteBundle( hr = CacheGetCompletedPath(pCache, pPackage->fPerMachine, pPackage->sczCacheId, &sczCachedDirectory); ExitOnFailure(hr, "Failed to get cached path for package: %ls", pPackage->sczId); - hr = PathConcatRelativeToBase(sczCachedDirectory, pPackagePayload->sczFilePath, &sczExecutablePath); + hr = PathConcatRelativeToFullyQualifiedBase(sczCachedDirectory, pPackagePayload->sczFilePath, &sczExecutablePath); ExitOnFailure(hr, "Failed to build executable path."); } diff --git a/src/burn/engine/cache.cpp b/src/burn/engine/cache.cpp index 5eacb20d..cf9de1c3 100644 --- a/src/burn/engine/cache.cpp +++ b/src/burn/engine/cache.cpp @@ -188,13 +188,18 @@ extern "C" HRESULT CacheInitialize( hr = PolcReadString(POLICY_BURN_REGISTRY_PATH, L"PackageCache", NULL, &pCache->sczCurrentMachinePackageCache); ExitOnFailure(hr, "Failed to read PackageCache policy directory."); - if (pCache->sczCurrentMachinePackageCache) + if (pCache->sczCurrentMachinePackageCache && PathIsFullyQualified(pCache->sczCurrentMachinePackageCache)) { hr = PathBackslashTerminate(&pCache->sczCurrentMachinePackageCache); ExitOnFailure(hr, "Failed to backslash terminate redirected per-machine package cache directory name."); } else { + if (pCache->sczCurrentMachinePackageCache) + { + LogErrorId(E_INVALIDARG, MSG_INVALID_POLICY_MACHINE_PACKAGE_CACHE, pCache->sczCurrentMachinePackageCache, NULL, NULL); + } + hr = StrAllocString(&pCache->sczCurrentMachinePackageCache, pCache->sczDefaultMachinePackageCache, 0); ExitOnFailure(hr, "Failed to copy default package cache directory to current package cache directory."); } @@ -251,7 +256,7 @@ extern "C" HRESULT CacheInitializeSources( hr = CacheGetCompletedPath(pCache, pRegistration->fPerMachine, pRegistration->sczId, &sczCompletedFolder); ExitOnFailure(hr, "Failed to get completed path for bundle."); - hr = PathConcatRelativeToBase(sczCompletedFolder, pRegistration->sczExecutableName, &sczCompletedPath); + hr = PathConcatRelativeToFullyQualifiedBase(sczCompletedFolder, pRegistration->sczExecutableName, &sczCompletedPath); ExitOnFailure(hr, "Failed to combine working path with engine file name."); hr = PathCompareCanonicalized(sczCurrentPath, sczCompletedPath, &fPathEqual); @@ -342,15 +347,16 @@ extern "C" HRESULT CacheEnsureBaseWorkingFolder( { for (DWORD i = 0; i < pCache->cPotentialBaseWorkingFolders; ++i) { - hr = PathConcatRelativeToBase(pCache->rgsczPotentialBaseWorkingFolders[i], pCache->wzGuid, &sczPotential); - ExitOnFailure(hr, "Failed to append random guid on to potential path for working folder."); - - hr = DirEnsureExists(sczPotential, NULL); + hr = PathConcatRelativeToFullyQualifiedBase(pCache->rgsczPotentialBaseWorkingFolders[i], pCache->wzGuid, &sczPotential); if (SUCCEEDED(hr)) { - pCache->sczBaseWorkingFolder = sczPotential; - sczPotential = NULL; - break; + hr = DirEnsureExists(sczPotential, NULL); + if (SUCCEEDED(hr)) + { + pCache->sczBaseWorkingFolder = sczPotential; + sczPotential = NULL; + break; + } } LogErrorId(hr, MSG_INVALID_BASE_WORKING_FOLDER, sczPotential, NULL, NULL); @@ -414,7 +420,7 @@ extern "C" HRESULT CacheCalculateBundleLayoutWorkingPath( HRESULT hr = S_OK; - hr = PathConcatRelativeToBase(pCache->sczAcquisitionFolder, wzBundleId, psczWorkingPath); + hr = PathConcatRelativeToFullyQualifiedBase(pCache->sczAcquisitionFolder, wzBundleId, psczWorkingPath); ExitOnFailure(hr, "Failed to append bundle id for bundle layout working path."); LExit: @@ -431,7 +437,7 @@ extern "C" HRESULT CacheCalculatePayloadWorkingPath( HRESULT hr = S_OK; - hr = PathConcatRelativeToBase(pCache->sczAcquisitionFolder, pPayload->sczKey, psczWorkingPath); + hr = PathConcatRelativeToFullyQualifiedBase(pCache->sczAcquisitionFolder, pPayload->sczKey, psczWorkingPath); ExitOnFailure(hr, "Failed to append Id as payload unverified path."); LExit: @@ -448,7 +454,7 @@ extern "C" HRESULT CacheCalculateContainerWorkingPath( HRESULT hr = S_OK; - hr = PathConcatRelativeToBase(pCache->sczAcquisitionFolder, pContainer->sczHash, psczWorkingPath); + hr = PathConcatRelativeToFullyQualifiedBase(pCache->sczAcquisitionFolder, pContainer->sczHash, psczWorkingPath); ExitOnFailure(hr, "Failed to append hash as container unverified path."); LExit: @@ -503,7 +509,7 @@ extern "C" HRESULT CacheGetCompletedPath( // GetRootPath returns S_FALSE if the package cache is redirected elsewhere. fRedirected = S_FALSE == hr; - hr = PathConcatRelativeToBase(sczRootPath, wzCacheId, &sczCurrentCompletedPath); + hr = PathConcatRelativeToFullyQualifiedBase(sczRootPath, wzCacheId, &sczCurrentCompletedPath); ExitOnFailure(hr, "Failed to construct cache path."); hr = PathBackslashTerminate(&sczCurrentCompletedPath); @@ -516,7 +522,7 @@ extern "C" HRESULT CacheGetCompletedPath( hr = GetRootPath(pCache, fPerMachine, FALSE, &sczRootPath); ExitOnFailure(hr, "Failed to get old %hs package cache root directory.", fPerMachine ? "per-machine" : "per-user"); - hr = PathConcatRelativeToBase(sczRootPath, wzCacheId, &sczDefaultCompletedPath); + hr = PathConcatRelativeToFullyQualifiedBase(sczRootPath, wzCacheId, &sczDefaultCompletedPath); ExitOnFailure(hr, "Failed to construct cache path."); hr = PathBackslashTerminate(&sczDefaultCompletedPath); @@ -957,7 +963,7 @@ extern "C" HRESULT CacheLayoutBundle( HRESULT hr = S_OK; LPWSTR sczTargetPath = NULL; - hr = PathConcatRelativeToBase(wzLayoutDirectory, wzExecutableName, &sczTargetPath); + hr = PathConcatRelativeToFullyQualifiedBase(wzLayoutDirectory, wzExecutableName, &sczTargetPath); ExitOnFailure(hr, "Failed to combine completed path with engine file name for layout."); LogStringLine(REPORT_STANDARD, "Layout bundle from: '%ls' to: '%ls'", wzSourceBundlePath, sczTargetPath); @@ -992,7 +998,7 @@ extern "C" HRESULT CacheCompleteBundle( hr = CreateCompletedPath(pCache, fPerMachine, wzBundleId, NULL, &sczTargetDirectory); ExitOnFailure(hr, "Failed to create completed cache path for bundle."); - hr = PathConcatRelativeToBase(sczTargetDirectory, wzExecutableName, &sczTargetPath); + hr = PathConcatRelativeToFullyQualifiedBase(sczTargetDirectory, wzExecutableName, &sczTargetPath); ExitOnFailure(hr, "Failed to combine completed path with engine file name."); // We can't just use wzExecutablePath because we needed to call CreateCompletedPath to ensure that the destination was secured. @@ -1045,7 +1051,7 @@ extern "C" HRESULT CacheLayoutContainer( HRESULT hr = S_OK; LPWSTR sczCachedPath = NULL; - hr = PathConcatRelativeToBase(wzLayoutDirectory, pContainer->sczFilePath, &sczCachedPath); + hr = PathConcatRelativeToFullyQualifiedBase(wzLayoutDirectory, pContainer->sczFilePath, &sczCachedPath); ExitOnFailure(hr, "Failed to concat complete cached path."); hr = VerifyThenTransferContainer(pContainer, sczCachedPath, wzUnverifiedContainerPath, fMove, pfnCacheMessageHandler, pfnProgress, pContext); @@ -1070,7 +1076,7 @@ extern "C" HRESULT CacheLayoutPayload( HRESULT hr = S_OK; LPWSTR sczCachedPath = NULL; - hr = PathConcatRelativeToBase(wzLayoutDirectory, pPayload->sczFilePath, &sczCachedPath); + hr = PathConcatRelativeToFullyQualifiedBase(wzLayoutDirectory, pPayload->sczFilePath, &sczCachedPath); ExitOnFailure(hr, "Failed to concat complete cached path."); hr = VerifyThenTransferPayload(pPayload, sczCachedPath, wzUnverifiedPayloadPath, fMove, pfnCacheMessageHandler, pfnProgress, pContext); @@ -1165,7 +1171,7 @@ extern "C" HRESULT CacheVerifyContainer( HRESULT hr = S_OK; LPWSTR sczCachedPath = NULL; - hr = PathConcatRelativeToBase(wzCachedDirectory, pContainer->sczFilePath, &sczCachedPath); + hr = PathConcatRelativeToFullyQualifiedBase(wzCachedDirectory, pContainer->sczFilePath, &sczCachedPath); ExitOnFailure(hr, "Failed to concat complete cached path."); hr = VerifyFileAgainstContainer(pContainer, sczCachedPath, TRUE, BURN_CACHE_STEP_HASH_TO_SKIP_ACQUIRE, pfnCacheMessageHandler, pfnProgress, pContext); @@ -1187,7 +1193,7 @@ extern "C" HRESULT CacheVerifyPayload( HRESULT hr = S_OK; LPWSTR sczCachedPath = NULL; - hr = PathConcatRelativeToBase(wzCachedDirectory, pPayload->sczFilePath, &sczCachedPath); + hr = PathConcatRelativeToFullyQualifiedBase(wzCachedDirectory, pPayload->sczFilePath, &sczCachedPath); ExitOnFailure(hr, "Failed to concat complete cached path."); hr = VerifyFileAgainstPayload(pPayload, sczCachedPath, TRUE, BURN_CACHE_STEP_HASH_TO_SKIP_ACQUIRE, pfnCacheMessageHandler, pfnProgress, pContext); @@ -1478,7 +1484,7 @@ static HRESULT CalculateWorkingFolders( pCache->wzGuid[GUID_STRING_LENGTH - 1] = L'\\'; pCache->wzGuid[GUID_STRING_LENGTH] = L'\0'; - hr = PathConcatRelativeToBase(sczBaseAcquisitionPath, pCache->wzGuid, &pCache->sczAcquisitionFolder); + hr = PathConcatRelativeToFullyQualifiedBase(sczBaseAcquisitionPath, pCache->wzGuid, &pCache->sczAcquisitionFolder); ExitOnFailure(hr, "Failed to append random guid on to temp path for acquisition folder."); LExit: @@ -1626,7 +1632,7 @@ static HRESULT CreateCompletedPath( else { // Get the cache completed file path. - hr = PathConcatRelativeToBase(sczCacheDirectory, wzFilePath, &sczCacheFile); + hr = PathConcatRelativeToFullyQualifiedBase(sczCacheDirectory, wzFilePath, &sczCacheFile); ExitOnFailure(hr, "Failed to construct cache file."); // Don't reset permissions here. The payload's package must reset its cache folder when it starts caching. @@ -1664,7 +1670,7 @@ static HRESULT CreateUnverifiedPath( pCache->fUnverifiedCacheFolderCreated = TRUE; } - hr = PathConcatRelativeToBase(sczUnverifiedCacheFolder, wzPayloadId, psczUnverifiedPayloadPath); + hr = PathConcatRelativeToFullyQualifiedBase(sczUnverifiedCacheFolder, wzPayloadId, psczUnverifiedPayloadPath); ExitOnFailure(hr, "Failed to concat payload id to unverified folder path."); LExit: @@ -2085,13 +2091,13 @@ static HRESULT CopyEngineToWorkingFolder( hr = CacheEnsureBaseWorkingFolder(pCache, &sczWorkingFolder); ExitOnFailure(hr, "Failed to create working path to copy engine."); - hr = PathConcatRelativeToBase(sczWorkingFolder, wzWorkingFolderName, &sczTargetDirectory); + hr = PathConcatRelativeToFullyQualifiedBase(sczWorkingFolder, wzWorkingFolderName, &sczTargetDirectory); ExitOnFailure(hr, "Failed to calculate the bundle working folder target name."); hr = DirEnsureExists(sczTargetDirectory, NULL); ExitOnFailure(hr, "Failed create bundle working folder."); - hr = PathConcatRelativeToBase(sczTargetDirectory, wzExecutableName, &sczTargetPath); + hr = PathConcatRelativeToFullyQualifiedBase(sczTargetDirectory, wzExecutableName, &sczTargetPath); ExitOnFailure(hr, "Failed to combine working path with engine file name."); // Copy the engine without any attached containers to the working path. diff --git a/src/burn/engine/core.cpp b/src/burn/engine/core.cpp index 39836bce..8dfa0010 100644 --- a/src/burn/engine/core.cpp +++ b/src/burn/engine/core.cpp @@ -2211,7 +2211,7 @@ static HRESULT DetectPackagePayloadsCached( { BURN_PAYLOAD* pPayload = pPackage->payloads.rgItems[i].pPayload; - hr = PathConcatRelativeToBase(sczCachePath, pPayload->sczFilePath, &sczPayloadCachePath); + hr = PathConcatRelativeToFullyQualifiedBase(sczCachePath, pPayload->sczFilePath, &sczPayloadCachePath); ExitOnFailure(hr, "Failed to concat payload cache path."); if (FileExistsEx(sczPayloadCachePath, NULL)) diff --git a/src/burn/engine/engine.mc b/src/burn/engine/engine.mc index 9a08fa3f..1c03145b 100644 --- a/src/burn/engine/engine.mc +++ b/src/burn/engine/engine.mc @@ -163,6 +163,13 @@ Language=English Failed to use folder as base working folder: %2!ls!, encountered error: %1!ls!. . +MessageId=20 +Severity=Warning +SymbolicName=MSG_INVALID_POLICY_MACHINE_PACKAGE_CACHE +Language=English +Failed to use folder as machine package cache: %2!ls!, encountered error: %1!ls!. +. + MessageId=51 Severity=Error SymbolicName=MSG_FAILED_PARSE_CONDITION diff --git a/src/burn/engine/exeengine.cpp b/src/burn/engine/exeengine.cpp index fb852c78..808577bc 100644 --- a/src/burn/engine/exeengine.cpp +++ b/src/burn/engine/exeengine.cpp @@ -380,7 +380,7 @@ extern "C" HRESULT ExeEngineExecutePackage( hr = CacheGetCompletedPath(pCache, pPackage->fPerMachine, pPackage->sczCacheId, &sczCachedDirectory); ExitOnFailure(hr, "Failed to get cached path for package: %ls", pPackage->sczId); - hr = PathConcatRelativeToBase(sczCachedDirectory, pPackagePayload->sczFilePath, &sczExecutablePath); + hr = PathConcatRelativeToFullyQualifiedBase(sczCachedDirectory, pPackagePayload->sczFilePath, &sczExecutablePath); ExitOnFailure(hr, "Failed to build executable path."); } diff --git a/src/burn/engine/msiengine.cpp b/src/burn/engine/msiengine.cpp index bfd5710f..edbf4d45 100644 --- a/src/burn/engine/msiengine.cpp +++ b/src/burn/engine/msiengine.cpp @@ -1236,7 +1236,7 @@ extern "C" HRESULT MsiEngineExecutePackage( // Best effort to set the execute package cache folder variable. VariableSetString(pVariables, BURN_BUNDLE_EXECUTE_PACKAGE_CACHE_FOLDER, sczCachedDirectory, TRUE, FALSE); - hr = PathConcatRelativeToBase(sczCachedDirectory, pPackagePayload->sczFilePath, &sczMsiPath); + hr = PathConcatRelativeToFullyQualifiedBase(sczCachedDirectory, pPackagePayload->sczFilePath, &sczMsiPath); ExitOnFailure(hr, "Failed to build MSI path."); } @@ -2195,7 +2195,7 @@ static HRESULT ConcatPatchProperty( hr = CacheGetCompletedPath(pCache, pMspPackage->fPerMachine, pMspPackage->sczCacheId, &sczCachedDirectory); ExitOnFailure(hr, "Failed to get cached path for MSP package: %ls", pMspPackage->sczId); - hr = PathConcatRelativeToBase(sczCachedDirectory, pMspPackagePayload->sczFilePath, &sczMspPath); + hr = PathConcatRelativeToFullyQualifiedBase(sczCachedDirectory, pMspPackagePayload->sczFilePath, &sczMspPath); ExitOnFailure(hr, "Failed to build MSP path."); if (!sczPatches) diff --git a/src/burn/engine/mspengine.cpp b/src/burn/engine/mspengine.cpp index 02e2afe4..81b7b651 100644 --- a/src/burn/engine/mspengine.cpp +++ b/src/burn/engine/mspengine.cpp @@ -613,7 +613,7 @@ extern "C" HRESULT MspEngineExecutePackage( // Best effort to set the execute package cache folder variable. VariableSetString(pVariables, BURN_BUNDLE_EXECUTE_PACKAGE_CACHE_FOLDER, sczCachedDirectory, TRUE, FALSE); - hr = PathConcatRelativeToBase(sczCachedDirectory, pMspPackagePayload->sczFilePath, &sczMspPath); + hr = PathConcatRelativeToFullyQualifiedBase(sczCachedDirectory, pMspPackagePayload->sczFilePath, &sczMspPath); ExitOnFailure(hr, "Failed to build MSP path."); wzAppend = sczMspPath; diff --git a/src/burn/engine/msuengine.cpp b/src/burn/engine/msuengine.cpp index d78943ac..1b051165 100644 --- a/src/burn/engine/msuengine.cpp +++ b/src/burn/engine/msuengine.cpp @@ -320,7 +320,7 @@ extern "C" HRESULT MsuEngineExecutePackage( // Best effort to set the execute package cache folder variable. VariableSetString(pVariables, BURN_BUNDLE_EXECUTE_PACKAGE_CACHE_FOLDER, sczCachedDirectory, TRUE, FALSE); - hr = PathConcatRelativeToBase(sczCachedDirectory, pPackagePayload->sczFilePath, &sczMsuPath); + hr = PathConcatRelativeToFullyQualifiedBase(sczCachedDirectory, pPackagePayload->sczFilePath, &sczMsuPath); ExitOnFailure(hr, "Failed to build MSU path."); // format command diff --git a/src/burn/engine/payload.cpp b/src/burn/engine/payload.cpp index f57f1310..a4450bf7 100644 --- a/src/burn/engine/payload.cpp +++ b/src/burn/engine/payload.cpp @@ -294,7 +294,7 @@ extern "C" HRESULT PayloadExtractUXContainer( ExitOnFailure(hr, "Failed to find embedded payload: %ls", sczStreamName); // make file path - hr = PathConcatRelativeToBase(wzTargetDir, pPayload->sczFilePath, &pPayload->sczLocalFilePath); + hr = PathConcatRelativeToFullyQualifiedBase(wzTargetDir, pPayload->sczFilePath, &pPayload->sczLocalFilePath); ExitOnFailure(hr, "Failed to concat file paths."); // extract file diff --git a/src/burn/engine/plan.cpp b/src/burn/engine/plan.cpp index 68c1d2ba..52bf6298 100644 --- a/src/burn/engine/plan.cpp +++ b/src/burn/engine/plan.cpp @@ -432,24 +432,28 @@ extern "C" HRESULT PlanLayoutBundle( { HRESULT hr = S_OK; BURN_CACHE_ACTION* pCacheAction = NULL; + LPWSTR sczLayoutDirectory = NULL; LPWSTR sczExecutablePath = NULL; // Get the layout directory. - hr = VariableGetString(pVariables, BURN_BUNDLE_LAYOUT_DIRECTORY, &pPlan->sczLayoutDirectory); + hr = VariableGetString(pVariables, BURN_BUNDLE_LAYOUT_DIRECTORY, &sczLayoutDirectory); if (E_NOTFOUND == hr) // if not set, use the current directory as the layout directory. { - hr = VariableGetString(pVariables, BURN_BUNDLE_SOURCE_PROCESS_FOLDER, &pPlan->sczLayoutDirectory); + hr = VariableGetString(pVariables, BURN_BUNDLE_SOURCE_PROCESS_FOLDER, &sczLayoutDirectory); if (E_NOTFOUND == hr) // if not set, use the current directory as the layout directory. { hr = PathForCurrentProcess(&sczExecutablePath, NULL); ExitOnFailure(hr, "Failed to get path for current executing process as layout directory."); - hr = PathGetDirectory(sczExecutablePath, &pPlan->sczLayoutDirectory); + hr = PathGetDirectory(sczExecutablePath, &sczLayoutDirectory); ExitOnFailure(hr, "Failed to get executing process as layout directory."); } } ExitOnFailure(hr, "Failed to get bundle layout directory property."); + hr = PathGetFullPathName(sczLayoutDirectory, &pPlan->sczLayoutDirectory, NULL, NULL); + ExitOnFailure(hr, "Failed to ensure layout directory is fully qualified."); + hr = PathBackslashTerminate(&pPlan->sczLayoutDirectory); ExitOnFailure(hr, "Failed to ensure layout directory is backslash terminated."); @@ -478,6 +482,7 @@ extern "C" HRESULT PlanLayoutBundle( LExit: ReleaseStr(sczExecutablePath); + ReleaseStr(sczLayoutDirectory); return hr; } diff --git a/src/burn/engine/registration.cpp b/src/burn/engine/registration.cpp index 2b3dc4d4..d0e5c677 100644 --- a/src/burn/engine/registration.cpp +++ b/src/burn/engine/registration.cpp @@ -1149,7 +1149,7 @@ static HRESULT SetPaths( ExitOnFailure(hr, "Failed to build cache directory."); // build cached executable path - hr = PathConcatRelativeToBase(sczCacheDirectory, pRegistration->sczExecutableName, &pRegistration->sczCacheExecutablePath); + hr = PathConcatRelativeToFullyQualifiedBase(sczCacheDirectory, pRegistration->sczExecutableName, &pRegistration->sczCacheExecutablePath); ExitOnFailure(hr, "Failed to build cached executable path."); // build state file path @@ -1367,7 +1367,7 @@ static HRESULT WriteSoftwareTags( hr = PathConcat(sczRootFolder, SWIDTAG_FOLDER, &sczTagFolder); ExitOnFailure(hr, "Failed to allocate regid folder path."); - hr = PathConcatRelativeToBase(sczTagFolder, pSoftwareTag->sczFilename, &sczPath); + hr = PathConcatRelativeToFullyQualifiedBase(sczTagFolder, pSoftwareTag->sczFilename, &sczPath); ExitOnFailure(hr, "Failed to allocate regid file path."); hr = DirEnsureExists(sczTagFolder, NULL); @@ -1405,7 +1405,7 @@ static HRESULT RemoveSoftwareTags( hr = PathConcat(sczRootFolder, SWIDTAG_FOLDER, &sczTagFolder); ExitOnFailure(hr, "Failed to allocate regid folder path."); - hr = PathConcatRelativeToBase(sczTagFolder, pSoftwareTag->sczFilename, &sczPath); + hr = PathConcatRelativeToFullyQualifiedBase(sczTagFolder, pSoftwareTag->sczFilename, &sczPath); ExitOnFailure(hr, "Failed to allocate regid file path."); // Best effort to delete the software tag file and the regid folder. diff --git a/src/libs/dutil/WixToolset.DUtil/inc/pathutil.h b/src/libs/dutil/WixToolset.DUtil/inc/pathutil.h index f36e6ebc..971ef887 100644 --- a/src/libs/dutil/WixToolset.DUtil/inc/pathutil.h +++ b/src/libs/dutil/WixToolset.DUtil/inc/pathutil.h @@ -298,6 +298,16 @@ DAPI_(HRESULT) PathConcatRelativeToBase( __deref_out_z LPWSTR* psczCombined ); +/******************************************************************* + PathConcatRelativeToFullyQualifiedBase - ensures the base path is + fully qualified and then calls PathConcatRelativeToBase. +*******************************************************************/ +DAPI_(HRESULT) PathConcatRelativeToFullyQualifiedBase( + __in LPCWSTR wzBase, + __in_opt LPCWSTR wzRelative, + __deref_out_z LPWSTR* psczCombined + ); + /******************************************************************* PathCompareCanonicalized - canonicalizes the two paths using PathCanonicalizeForComparison which does not resolve relative paths into fully qualified paths. diff --git a/src/libs/dutil/WixToolset.DUtil/path2utl.cpp b/src/libs/dutil/WixToolset.DUtil/path2utl.cpp index c6ff608c..3c4b2f88 100644 --- a/src/libs/dutil/WixToolset.DUtil/path2utl.cpp +++ b/src/libs/dutil/WixToolset.DUtil/path2utl.cpp @@ -162,6 +162,25 @@ LExit: return hr; } +DAPI_(HRESULT) PathConcatRelativeToFullyQualifiedBase( + __in LPCWSTR wzBase, + __in_opt LPCWSTR wzRelative, + __deref_out_z LPWSTR* psczCombined + ) +{ + HRESULT hr = S_OK; + + if (!PathIsFullyQualified(wzBase)) + { + PathExitWithRootFailure(hr, E_INVALIDARG, "wzBase must be fully qualified: %ls.", wzBase); + } + + hr = PathConcatRelativeToBase(wzBase, wzRelative, psczCombined); + +LExit: + return hr; +} + DAPI_(HRESULT) PathCompareCanonicalized( __in_z LPCWSTR wzPath1, __in_z LPCWSTR wzPath2, -- cgit v1.2.3-55-g6feb