Skip to content

Commit

Permalink
Drop CA path validation in WixUI by default.
Browse files Browse the repository at this point in the history
Add `WixUI/ExtendedPathValidation="yes"` to opt-in.
Removed the WIXUI_DONTVALIDATEPATH runtime opt-out.

Fixes wixtoolset/issues#8718
Relies on #563
  • Loading branch information
barnson committed Sep 28, 2024
1 parent 526a11b commit f8d1a71
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 96 deletions.
42 changes: 21 additions & 21 deletions src/ext/UI/ca/DriveCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,29 @@ static HRESULT PathIsRemovable(__in LPCWSTR pTargetFolder, __inout BOOL* fPathRe
UINT __stdcall ValidatePath(MSIHANDLE hInstall)
{
HRESULT hr = S_OK;

LPWSTR pwszWixUIDir = NULL;
LPWSTR pwszInstallPath = NULL;
BOOL fInstallPathIsRemote = TRUE;
BOOL fInstallPathIsRemoveable = TRUE;

hr = WcaInitialize(hInstall, "ValidatePath");
ExitOnFailure(hr, "failed to initialize");

hr = WcaGetProperty(L"WIXUI_INSTALLDIR", &pwszWixUIDir);
ExitOnFailure(hr, "failed to get WixUI Installation Directory");

hr = WcaGetProperty(pwszWixUIDir, &pwszInstallPath);
ExitOnFailure(hr, "failed to get Installation Directory");

hr = PathIsRemote(pwszInstallPath, &fInstallPathIsRemote);
if (FAILED(hr))
{
TraceError(hr, "Unable to determine if path is remote");
//reset HR, as we need to continue and find out if is a UNC path
hr = S_OK;
}

hr = PathIsRemovable(pwszInstallPath, &fInstallPathIsRemoveable);
if (FAILED(hr))
{
Expand All @@ -45,7 +45,7 @@ UINT __stdcall ValidatePath(MSIHANDLE hInstall)

// If the path does not point to a network drive, mapped drive, or removable drive,
// then set WIXUI_INSTALLDIR_VALID to "1" otherwise set it to 0
BOOL fInstallPathIsUnc = PathIsUNCW(pwszInstallPath);
BOOL fInstallPathIsUnc = ::PathIsUNCW(pwszInstallPath);
if (!fInstallPathIsUnc && !fInstallPathIsRemote && !fInstallPathIsRemoveable)
{
// path is valid
Expand All @@ -61,7 +61,7 @@ UINT __stdcall ValidatePath(MSIHANDLE hInstall)
hr = WcaSetProperty(L"WIXUI_INSTALLDIR_VALID", L"0");
ExitOnFailure(hr, "failed to set WIXUI_INSTALLDIR_VALID");
}

LExit:
ReleaseStr(pwszInstallPath);
ReleaseStr(pwszWixUIDir);
Expand All @@ -79,22 +79,22 @@ static HRESULT PathIsRemote(__in LPCWSTR pTargetFolder, __inout BOOL* fPathRemot
LPWSTR pStrippedTargetFolder = NULL;

hr = StrAllocString(&pStrippedTargetFolder, pTargetFolder, 0);

// Terminate the path at the root
if(!::PathStripToRootW(pStrippedTargetFolder))
if (!::PathStripToRootW(pStrippedTargetFolder))
{
hr = HRESULT_FROM_WIN32(ERROR_INVALID_DRIVE);
ExitOnFailure(hr, "failed to parse target folder");
ExitOnFailure(hr, "failed to parse target folder");
}
UINT uResult = GetDriveTypeW(pStrippedTargetFolder);
*fPathRemote = (DRIVE_REMOTE == uResult) ;

UINT uResult = ::GetDriveTypeW(pStrippedTargetFolder);

*fPathRemote = (DRIVE_REMOTE == uResult);

LExit:
ReleaseStr(pStrippedTargetFolder);

return hr;
return hr;
}

/********************************************************************
Expand All @@ -107,16 +107,16 @@ static HRESULT PathIsRemovable(__in LPCWSTR pTargetFolder, __inout BOOL* fPathRe
LPWSTR pStrippedTargetFolder = NULL;

hr = StrAllocString(&pStrippedTargetFolder, pTargetFolder, 0);

// Terminate the path at the root
if(!::PathStripToRootW(pStrippedTargetFolder))
if (!::PathStripToRootW(pStrippedTargetFolder))
{
hr = HRESULT_FROM_WIN32(ERROR_INVALID_DRIVE);
ExitOnFailure(hr, "failed to parse target folder");
ExitOnFailure(hr, "failed to parse target folder");
}
UINT uResult = GetDriveTypeW(pStrippedTargetFolder);

UINT uResult = ::GetDriveTypeW(pStrippedTargetFolder);

*fPathRemovable = ((DRIVE_CDROM == uResult) || (DRIVE_REMOVABLE == uResult) || (DRIVE_RAMDISK == uResult) || (DRIVE_UNKNOWN == uResult));

LExit:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
<?foreach WIXUIARCH in X86;X64;A64 ?>
<Fragment>
<UI Id="InstallDir_NoLicense_$(WIXUIARCH)">
<Publish Dialog="BrowseDlg" Control="OK" Event="DoAction" Value="WixUIValidatePath_$(WIXUIARCH)" Order="3" Condition="NOT WIXUI_DONTVALIDATEPATH" />
<Publish Dialog="InstallDirDlg" Control="Next" Event="DoAction" Value="WixUIValidatePath_$(WIXUIARCH)" Order="2" Condition="NOT WIXUI_DONTVALIDATEPATH" />
<Publish Dialog="BrowseDlg" Control="OK" Event="DoAction" Value="WixUIValidatePath_$(WIXUIARCH)" Order="3" />
<Publish Dialog="InstallDirDlg" Control="Next" Event="DoAction" Value="WixUIValidatePath_$(WIXUIARCH)" Order="2" />
</UI>

<UIRef Id="InstallDir_NoLicense" />
Expand All @@ -50,20 +50,21 @@
<DialogRef Id="ProgressDlg" />
<DialogRef Id="ResumeDlg" />
<DialogRef Id="UserExit" />

<Publish Dialog="BrowseDlg" Control="OK" Event="SpawnDialog" Value="InvalidDirDlg" Order="4" Condition="NOT WIXUI_DONTVALIDATEPATH AND WIXUI_INSTALLDIR_VALID&lt;&gt;&quot;1&quot;" />

<Publish Dialog="ExitDialog" Control="Finish" Event="EndDialog" Value="Return" Order="999" />

<Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="InstallDirDlg" Condition="NOT Installed" />
<Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="VerifyReadyDlg" Condition="Installed AND PATCH" />

<Publish Dialog="InstallDirDlg" Control="Back" Event="NewDialog" Value="WelcomeDlg" />
<Publish Dialog="InstallDirDlg" Control="Next" Event="SetTargetPath" Value="[WIXUI_INSTALLDIR]" Order="1" />
<Publish Dialog="InstallDirDlg" Control="Next" Event="SpawnDialog" Value="InvalidDirDlg" Order="3" Condition="NOT WIXUI_DONTVALIDATEPATH AND WIXUI_INSTALLDIR_VALID&lt;&gt;&quot;1&quot;" />
<Publish Dialog="InstallDirDlg" Control="Next" Event="NewDialog" Value="VerifyReadyDlg" Order="4" Condition="WIXUI_DONTVALIDATEPATH OR WIXUI_INSTALLDIR_VALID=&quot;1&quot;" />
<Publish Dialog="InstallDirDlg" Control="Next" Event="SetTargetPath" Value="[WIXUI_INSTALLDIR]" Order="3" />
<Publish Dialog="InstallDirDlg" Control="Next" Event="NewDialog" Value="VerifyReadyDlg" Order="4" />
<Publish Dialog="InstallDirDlg" Control="ChangeFolder" Property="_BrowseProperty" Value="[WIXUI_INSTALLDIR]" Order="1" />
<Publish Dialog="InstallDirDlg" Control="ChangeFolder" Event="SpawnDialog" Value="BrowseDlg" Order="2" />

<Publish Dialog="BrowseDlg" Control="OK" Event="SetTargetPath" Value="[_BrowseProperty]" Order="3" />
<Publish Dialog="BrowseDlg" Control="OK" Event="EndDialog" Value="Return" Order="4" />

<Publish Dialog="VerifyReadyDlg" Control="Back" Event="NewDialog" Value="InstallDirDlg" Order="1" Condition="NOT Installed" />
<Publish Dialog="VerifyReadyDlg" Control="Back" Event="NewDialog" Value="MaintenanceTypeDlg" Order="2" Condition="Installed AND NOT PATCH" />
<Publish Dialog="VerifyReadyDlg" Control="Back" Event="NewDialog" Value="WelcomeDlg" Order="2" Condition="Installed AND PATCH" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@

<?foreach WIXUIARCH in X86;X64;A64 ?>
<Fragment>
<UI Id="InstallDir_SpecialDlg_$(WIXUIARCH)">
<Publish Dialog="BrowseDlg" Control="OK" Event="DoAction" Value="WixUIValidatePath_$(WIXUIARCH)" Order="3" Condition="NOT WIXUI_DONTVALIDATEPATH" />
<Publish Dialog="InstallDirDlg" Control="Next" Event="DoAction" Value="WixUIValidatePath_$(WIXUIARCH)" Order="2" Condition="NOT WIXUI_DONTVALIDATEPATH" />
</UI>
<UI Id="InstallDir_SpecialDlg_$(WIXUIARCH)" />

<UIRef Id="InstallDir_SpecialDlg" />
</Fragment>
Expand All @@ -70,7 +67,7 @@
<DialogRef Id="ResumeDlg" />
<DialogRef Id="UserExit" />

<Publish Dialog="BrowseDlg" Control="OK" Event="SpawnDialog" Value="InvalidDirDlg" Order="4" Condition="NOT WIXUI_DONTVALIDATEPATH AND WIXUI_INSTALLDIR_VALID&lt;&gt;&quot;1&quot;" />
<Publish Dialog="BrowseDlg" Control="OK" Event="SpawnDialog" Value="InvalidDirDlg" Order="4" Condition="WIXUI_INSTALLDIR_VALID&lt;&gt;&quot;1&quot;" />

<Publish Dialog="ExitDialog" Control="Finish" Event="EndDialog" Value="Return" Order="999" />

Expand All @@ -85,8 +82,8 @@

<Publish Dialog="InstallDirDlg" Control="Back" Event="NewDialog" Value="LicenseAgreementDlg" />
<Publish Dialog="InstallDirDlg" Control="Next" Event="SetTargetPath" Value="[WIXUI_INSTALLDIR]" Order="1" />
<Publish Dialog="InstallDirDlg" Control="Next" Event="SpawnDialog" Value="InvalidDirDlg" Order="3" Condition="NOT WIXUI_DONTVALIDATEPATH AND WIXUI_INSTALLDIR_VALID&lt;&gt;&quot;1&quot;" />
<Publish Dialog="InstallDirDlg" Control="Next" Event="NewDialog" Value="VerifyReadyDlg" Order="4" Condition="WIXUI_DONTVALIDATEPATH OR WIXUI_INSTALLDIR_VALID=&quot;1&quot;" />
<Publish Dialog="InstallDirDlg" Control="Next" Event="SpawnDialog" Value="InvalidDirDlg" Order="3" Condition="WIXUI_INSTALLDIR_VALID&lt;&gt;&quot;1&quot;" />
<Publish Dialog="InstallDirDlg" Control="Next" Event="NewDialog" Value="VerifyReadyDlg" Order="4" Condition="WIXUI_INSTALLDIR_VALID=&quot;1&quot;" />
<Publish Dialog="InstallDirDlg" Control="ChangeFolder" Property="_BrowseProperty" Value="[WIXUI_INSTALLDIR]" Order="1" />
<Publish Dialog="InstallDirDlg" Control="ChangeFolder" Event="SpawnDialog" Value="BrowseDlg" Order="2" />
<Publish Dialog="VerifyReadyDlg" Control="Back" Event="NewDialog" Value="InstallDirDlg" Order="1" Condition="NOT Installed" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs" xmlns:ui="http://wixtoolset.org/schemas/v4/wxs/ui">
<Package Name="MsiPackage" Language="1033" Version="1.0.0.0" Manufacturer="Example Corporation" UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a">
<Package Name="WixUI_Advanced" Language="1033" Version="1.0.0.0" Manufacturer="Example Corporation" UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a">
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />

<Feature Id="ProductFeature" Title="MsiPackage">
<ComponentGroupRef Id="ProductComponents" />
</Feature>

<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<ComponentGroup Id="ProductComponents" Directory="APPLICATIONFOLDER">
<Component>
<File Source="example.txt" />
</Component>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs" xmlns:ui="http://wixtoolset.org/schemas/v4/wxs/ui">
<Package Name="MsiPackage" Language="1033" Version="1.0.0.0" Manufacturer="Example Corporation" UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a" InstallerVersion="200">
<Package Name="WixUI_InstallDir" Language="1033" Version="1.0.0.0" Manufacturer="Example Corporation" UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a" InstallerVersion="200">
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />

<Feature Id="ProductFeature" Title="MsiPackage">
Expand All @@ -12,7 +12,7 @@
</Component>
</ComponentGroup>

<ui:WixUI Id="WixUI_InstallDir" InstallDirectory="INSTALLFOLDER" />
<ui:WixUI Id="WixUI_InstallDir" InstallDirectory="INSTALLFOLDER" ExtendedPathValidation="yes" />
</Package>

<Fragment>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs" xmlns:ui="http://wixtoolset.org/schemas/v4/wxs/ui">
<Package Name="MsiPackage" Language="1033" Version="1.0.0.0" Manufacturer="Example Corporation" UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a" InstallerVersion="200">
<Package Name="WixUI_Mondo" Language="1033" Version="1.0.0.0" Manufacturer="Example Corporation" UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a" InstallerVersion="200">
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />

<Feature Id="ProductFeature" Title="MsiPackage">
<Feature Id="ProductFeature" Title="MsiPackage" ConfigurableDirectory="INSTALLFOLDER">
<ComponentGroupRef Id="ProductComponents" />
</Feature>

Expand All @@ -12,7 +12,7 @@
</Component>
</ComponentGroup>

<ui:WixUI Id="WixUI_Mondo" />
<ui:WixUI Id="WixUI_Mondo" ExtendedPathValidation="yes" />
<WixVariable Id="WixUILicenseRtf" Value="bpl.rtf" />
</Package>

Expand Down
Loading

0 comments on commit f8d1a71

Please sign in to comment.