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.

Fixes wixtoolset/issues#8718
Relies on #563
  • Loading branch information
barnson committed Sep 28, 2024
1 parent 526a11b commit 8bf70b9
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 47 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 @@ -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
Expand Up @@ -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
24 changes: 3 additions & 21 deletions src/ext/UI/test/WixToolsetTest.UI/UIExtensionFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,15 @@ public void CanBuildUsingWixUIAdvanced()
"Binary:WixUI_Bmp_Up\t[Binary data]",
"Binary:WixUI_Ico_Exclam\t[Binary data]",
"Binary:WixUI_Ico_Info\t[Binary data]",
"Binary:WixUiCa_X86\t[Binary data]",
}, results.Where(r => r.StartsWith("Binary:")).ToArray());
WixAssert.CompareLineByLine(new[]
{
"CustomAction:WixSetDefaultPerMachineFolder\t51\tWixPerMachineFolder\t[ProgramFilesFolder][ApplicationFolderName]\t",
"CustomAction:WixSetDefaultPerUserFolder\t51\tWixPerUserFolder\t[LocalAppDataFolder]Apps\\[ApplicationFolderName]\t",
"CustomAction:WixSetPerMachineFolder\t51\tAPPLICATIONFOLDER\t[WixPerMachineFolder]\t",
"CustomAction:WixSetPerUserFolder\t51\tAPPLICATIONFOLDER\t[WixPerUserFolder]\t",
"CustomAction:WixUIValidatePath_X86\t65\tWixUiCa_X86\tValidatePath\t",
}, results.Where(r => r.StartsWith("CustomAction:")).ToArray());
WixAssert.CompareLineByLine(new[]
{
"ControlEvent:BrowseDlg\tOK\tDoAction\tWixUIValidatePath_X86\tNOT WIXUI_DONTVALIDATEPATH\t1",
"ControlEvent:InstallDirDlg\tNext\tDoAction\tWixUIValidatePath_X86\tNOT WIXUI_DONTVALIDATEPATH\t2",
}, results.Where(result => result.StartsWith("ControlEvent:") && result.Contains("DoAction")).ToArray());
Assert.Empty(results.Where(result => result.StartsWith("ControlEvent:") && result.Contains("DoAction")).ToArray());
WixAssert.CompareLineByLine(new[]
{
"InstallUISequence:AdvancedWelcomeEulaDlg\tNOT Installed\t1297",
Expand All @@ -68,21 +62,15 @@ public void CanBuildUsingWixUIAdvancedX64()
"Binary:WixUI_Bmp_Up\t[Binary data]",
"Binary:WixUI_Ico_Exclam\t[Binary data]",
"Binary:WixUI_Ico_Info\t[Binary data]",
"Binary:WixUiCa_X64\t[Binary data]",
}, results.Where(r => r.StartsWith("Binary:")).ToArray());
WixAssert.CompareLineByLine(new[]
{
"CustomAction:WixSetDefaultPerMachineFolder\t51\tWixPerMachineFolder\t[ProgramFilesFolder][ApplicationFolderName]\t",
"CustomAction:WixSetDefaultPerUserFolder\t51\tWixPerUserFolder\t[LocalAppDataFolder]Apps\\[ApplicationFolderName]\t",
"CustomAction:WixSetPerMachineFolder\t51\tAPPLICATIONFOLDER\t[WixPerMachineFolder]\t",
"CustomAction:WixSetPerUserFolder\t51\tAPPLICATIONFOLDER\t[WixPerUserFolder]\t",
"CustomAction:WixUIValidatePath_X64\t65\tWixUiCa_X64\tValidatePath\t",
}, results.Where(r => r.StartsWith("CustomAction:")).ToArray());
WixAssert.CompareLineByLine(new[]
{
"ControlEvent:BrowseDlg\tOK\tDoAction\tWixUIValidatePath_X64\tNOT WIXUI_DONTVALIDATEPATH\t1",
"ControlEvent:InstallDirDlg\tNext\tDoAction\tWixUIValidatePath_X64\tNOT WIXUI_DONTVALIDATEPATH\t2",
}, results.Where(result => result.StartsWith("ControlEvent:") && result.Contains("DoAction")).ToArray());
Assert.Empty(results.Where(result => result.StartsWith("ControlEvent:") && result.Contains("DoAction")).ToArray());
}

[Fact]
Expand All @@ -102,21 +90,15 @@ public void CanBuildUsingWixUIAdvancedARM64()
"Binary:WixUI_Bmp_Up\t[Binary data]",
"Binary:WixUI_Ico_Exclam\t[Binary data]",
"Binary:WixUI_Ico_Info\t[Binary data]",
"Binary:WixUiCa_A64\t[Binary data]",
}, results.Where(r => r.StartsWith("Binary:")).ToArray());
WixAssert.CompareLineByLine(new[]
{
"CustomAction:WixSetDefaultPerMachineFolder\t51\tWixPerMachineFolder\t[ProgramFilesFolder][ApplicationFolderName]\t",
"CustomAction:WixSetDefaultPerUserFolder\t51\tWixPerUserFolder\t[LocalAppDataFolder]Apps\\[ApplicationFolderName]\t",
"CustomAction:WixSetPerMachineFolder\t51\tAPPLICATIONFOLDER\t[WixPerMachineFolder]\t",
"CustomAction:WixSetPerUserFolder\t51\tAPPLICATIONFOLDER\t[WixPerUserFolder]\t",
"CustomAction:WixUIValidatePath_A64\t65\tWixUiCa_A64\tValidatePath\t",
}, results.Where(r => r.StartsWith("CustomAction:")).ToArray());
WixAssert.CompareLineByLine(new[]
{
"ControlEvent:BrowseDlg\tOK\tDoAction\tWixUIValidatePath_A64\tNOT WIXUI_DONTVALIDATEPATH\t1",
"ControlEvent:InstallDirDlg\tNext\tDoAction\tWixUIValidatePath_A64\tNOT WIXUI_DONTVALIDATEPATH\t2",
}, results.Where(result => result.StartsWith("ControlEvent:") && result.Contains("DoAction")).ToArray());
Assert.Empty(results.Where(result => result.StartsWith("ControlEvent:") && result.Contains("DoAction")).ToArray());
}

[Fact]
Expand Down
14 changes: 13 additions & 1 deletion src/ext/UI/wixext/UICompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ private void ParseWixUIElement(Intermediate intermediate, IntermediateSection se
var sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element);
string id = null;
string installDirectory = null;
YesNoType extendedPathValidation = YesNoType.No;

foreach (var attrib in element.Attributes())
{
Expand All @@ -69,6 +70,9 @@ private void ParseWixUIElement(Intermediate intermediate, IntermediateSection se
case "InstallDirectory":
installDirectory = this.ParseHelper.GetAttributeIdentifierValue(sourceLineNumbers, attrib);
break;
case "ExtendedPathValidation":
extendedPathValidation = this.ParseHelper.GetAttributeYesNoValue(sourceLineNumbers, attrib);
break;
default:
this.ParseHelper.UnexpectedAttribute(element, attrib);
break;
Expand All @@ -87,7 +91,15 @@ private void ParseWixUIElement(Intermediate intermediate, IntermediateSection se
else
{
var platform = this.Context.Platform == Platform.ARM64 ? "A64" : this.Context.Platform.ToString();
this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, SymbolDefinitions.WixUI, $"{id}_{platform}");

if (extendedPathValidation == YesNoType.No)
{
this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, SymbolDefinitions.WixUI, $"{id}_{platform}");
}
else
{
this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, SymbolDefinitions.WixUI, $"{id}_ExtendedPathValidation_{platform}");
}

if (installDirectory != null)
{
Expand Down
16 changes: 14 additions & 2 deletions src/ext/UI/wixlib/WixUI_Advanced.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,22 @@ Todo:
<?foreach WIXUIARCH in X86;X64;A64 ?>
<Fragment>
<UI Id="WixUI_Advanced_$(WIXUIARCH)">
<Publish Dialog="BrowseDlg" Control="OK" Event="CheckTargetPath" Value="[WIXUI_INSTALLDIR]" Order="1" Condition="NOT WIXUI_DONTVALIDATEPATH" />
<Publish Dialog="InstallDirDlg" Control="Next" Event="CheckTargetPath" Value="[WIXUI_INSTALLDIR]" Order="2" Condition="NOT WIXUI_DONTVALIDATEPATH" />
</UI>

<UIRef Id="WixUI_Advanced" />
</Fragment>
<?endforeach?>

<?foreach WIXUIARCH in X86;X64;A64 ?>
<Fragment>
<UI Id="WixUI_Advanced_ExtendedPathValidation_$(WIXUIARCH)">
<Publish Dialog="BrowseDlg" Control="OK" Event="DoAction" Value="WixUIValidatePath_$(WIXUIARCH)" Order="1" Condition="NOT WIXUI_DONTVALIDATEPATH" />
<Publish Dialog="BrowseDlg" Control="OK" Event="SpawnDialog" Value="InvalidDirDlg" Order="2" Condition="WIXUI_INSTALLDIR_VALID&lt;&gt;&quot;1&quot;" />

<Publish Dialog="InstallDirDlg" Control="Next" Event="DoAction" Value="WixUIValidatePath_$(WIXUIARCH)" Order="2" Condition="NOT WIXUI_DONTVALIDATEPATH" />
<Publish Dialog="InstallDirDlg" Control="Next" Event="SpawnDialog" Value="InvalidDirDlg" Order="3" Condition="NOT WIXUI_DONTVALIDATEPATH AND WIXUI_INSTALLDIR_VALID&lt;&gt;&quot;1&quot;" />
</UI>

<UIRef Id="WixUI_Advanced" />
Expand Down Expand Up @@ -76,7 +90,6 @@ Todo:
<DialogRef Id="WelcomeDlg" />

<Publish Dialog="ExitDialog" Control="Finish" Event="EndDialog" Value="Return" Order="999" />
<Publish Dialog="BrowseDlg" Control="OK" Event="SpawnDialog" Value="InvalidDirDlg" Order="2" Condition="WIXUI_INSTALLDIR_VALID&lt;&gt;&quot;1&quot;" />

<Publish Dialog="AdvancedWelcomeEulaDlg" Control="Advanced" Event="NewDialog" Value="InstallScopeDlg" Order="1" Condition="!(wix.WixUISupportPerMachine) AND !(wix.WixUISupportPerUser)" />
<Publish Dialog="AdvancedWelcomeEulaDlg" Control="Advanced" Event="NewDialog" Value="FeaturesDlg" Order="2" Condition="NOT !(wix.WixUISupportPerMachine)" />
Expand All @@ -95,7 +108,6 @@ Todo:
<Publish Dialog="InstallDirDlg" Control="Back" Event="NewDialog" Value="InstallScopeDlg" Condition="!(wix.WixUISupportPerUser)" />
<Publish Dialog="InstallDirDlg" Control="Back" Event="NewDialog" Value="AdvancedWelcomeEulaDlg" Condition="NOT !(wix.WixUISupportPerUser)" />
<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="FeaturesDlg" Order="4" Condition="WIXUI_DONTVALIDATEPATH OR 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" />
Expand Down
11 changes: 11 additions & 0 deletions src/ext/UI/wixlib/WixUI_InstallDir.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ Patch dialog sequence:
<?foreach WIXUIARCH in X86;X64;A64 ?>
<Fragment>
<UI Id="WixUI_InstallDir_$(WIXUIARCH)">
<Publish Dialog="BrowseDlg" Control="OK" Event="CheckTargetPath" Value="[WIXUI_INSTALLDIR]" Order="3" Condition="NOT WIXUI_DONTVALIDATEPATH" />
<Publish Dialog="InstallDirDlg" Control="Next" Event="CheckTargetPath" Value="[WIXUI_INSTALLDIR]" Order="2" Condition="NOT WIXUI_DONTVALIDATEPATH" />
</UI>

<UIRef Id="WixUI_InstallDir" />
</Fragment>
<?endforeach?>

<?foreach WIXUIARCH in X86;X64;A64 ?>
<Fragment>
<UI Id="WixUI_InstallDir_ExtendedPathValidation_$(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>
Expand Down
10 changes: 10 additions & 0 deletions src/ext/UI/wixlib/WixUI_Mondo.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ Patch dialog sequence:
<?foreach WIXUIARCH in X86;X64;A64 ?>
<Fragment>
<UI Id="WixUI_Mondo_$(WIXUIARCH)">
<Publish Dialog="BrowseDlg" Control="OK" Event="CheckTargetPath" Value="[WIXUI_INSTALLDIR]" Order="3" Condition="NOT WIXUI_DONTVALIDATEPATH" />
</UI>

<UIRef Id="WixUI_Mondo" />
</Fragment>
<?endforeach?>

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

Expand Down

0 comments on commit 8bf70b9

Please sign in to comment.