From 02b8f1a145724d889f95761390dc6223289764ac Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Fri, 11 Mar 2022 17:16:23 -0800 Subject: Always try to normalize the Bundle UpgradeCode in the backend Fixes 6008 --- .../WixToolset.Core.Burn/Bind/BindBundleCommand.cs | 16 ++++++++++++ .../BundleFixture.cs | 29 ++++++++++++++++++++++ .../BundleWithInvalidUpgradeCode.wxl | 3 +++ .../BundleWithInvalidUpgradeCode.wxs | 11 ++++++++ 4 files changed, 59 insertions(+) create mode 100644 src/wix/test/WixToolsetTest.CoreIntegration/TestData/BundleWithInvalid/BundleWithInvalidUpgradeCode.wxl create mode 100644 src/wix/test/WixToolsetTest.CoreIntegration/TestData/BundleWithInvalid/BundleWithInvalidUpgradeCode.wxs diff --git a/src/wix/WixToolset.Core.Burn/Bind/BindBundleCommand.cs b/src/wix/WixToolset.Core.Burn/Bind/BindBundleCommand.cs index 7b74ce5e..eb822fba 100644 --- a/src/wix/WixToolset.Core.Burn/Bind/BindBundleCommand.cs +++ b/src/wix/WixToolset.Core.Burn/Bind/BindBundleCommand.cs @@ -102,6 +102,8 @@ namespace WixToolset.Core.Burn bundleSymbol.ProviderKey = bundleSymbol.BundleId = Guid.NewGuid().ToString("B").ToUpperInvariant(); + bundleSymbol.UpgradeCode = this.NormalizeBundleUpgradeCode(bundleSymbol.SourceLineNumbers, bundleSymbol.UpgradeCode); + bundleSymbol.Attributes |= WixBundleAttributes.PerMachine; // default to per-machine but the first-per user package wil flip the bundle per-user. // Ensure there is one and only one WixBootstrapperApplicationDllSymbol. @@ -494,6 +496,20 @@ namespace WixToolset.Core.Burn this.Wixout = this.CreateWixout(trackedFiles, this.Output, manifestPath, baManifestPath, bextManifestPath); } + private string NormalizeBundleUpgradeCode(SourceLineNumber sourceLineNumber, string upgradeCode) + { + if (Guid.TryParse(upgradeCode, out var guid)) + { + return guid.ToString("B").ToUpperInvariant(); + } + else + { + this.Messaging.Write(ErrorMessages.IllegalGuidValue(sourceLineNumber, "Bundle", "UpgradeCode", upgradeCode)); + } + + return upgradeCode; + } + private WixOutput CreateWixout(List trackedFiles, Intermediate intermediate, string manifestPath, string baDataPath, string bextDataPath) { WixOutput wixout; diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/BundleFixture.cs b/src/wix/test/WixToolsetTest.CoreIntegration/BundleFixture.cs index 2328d762..77b122da 100644 --- a/src/wix/test/WixToolsetTest.CoreIntegration/BundleFixture.cs +++ b/src/wix/test/WixToolsetTest.CoreIntegration/BundleFixture.cs @@ -319,6 +319,35 @@ namespace WixToolsetTest.CoreIntegration } } + [Fact] + public void CannotBuildBundleWithInvalidUpgradeCode() + { + var folder = TestData.Get(@"TestData"); + + using (var fs = new DisposableFileSystem()) + { + var baseFolder = fs.GetFolder(); + var intermediateFolder = Path.Combine(baseFolder, "obj"); + + var result = WixRunner.Execute(new[] + { + "build", + Path.Combine(folder, "BundleWithInvalid", "BundleWithInvalidUpgradeCode.wxs"), + "-loc", Path.Combine(folder, "BundleWithInvalid", "BundleWithInvalidUpgradeCode.wxl"), + "-bindpath", Path.Combine(folder, ".Data"), + "-bindpath", Path.Combine(folder, "SimpleBundle", "data"), + "-intermediateFolder", intermediateFolder, + "-o", Path.Combine(baseFolder, @"bin\test.exe") + }); + + var message = result.Messages.Where(m => m.Level == MessageLevel.Error).Select(m => m.ToString().Replace(folder, "")).ToArray(); + WixAssert.CompareLineByLine(new[] + { + "The Bundle/@UpgradeCode attribute's value, 'NOT-A-GUID', is not a legal guid value." + }, message); + } + } + [Fact] public void CanBuildUncompressedBundle() { diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/BundleWithInvalid/BundleWithInvalidUpgradeCode.wxl b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/BundleWithInvalid/BundleWithInvalidUpgradeCode.wxl new file mode 100644 index 00000000..40688f36 --- /dev/null +++ b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/BundleWithInvalid/BundleWithInvalidUpgradeCode.wxl @@ -0,0 +1,3 @@ + + NOT-A-GUID + diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/BundleWithInvalid/BundleWithInvalidUpgradeCode.wxs b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/BundleWithInvalid/BundleWithInvalidUpgradeCode.wxs new file mode 100644 index 00000000..dce57226 --- /dev/null +++ b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/BundleWithInvalid/BundleWithInvalidUpgradeCode.wxs @@ -0,0 +1,11 @@ + + + + + + + + + + -- cgit v1.2.3-55-g6feb