commit 331d0ee8ff1e9c8841c34eb8ba4a38f1dd5fbbd9
parent ea9337683ae91d24400c0733c11b611f11a80eb3
Author: JohnMcPMS <johnmcp@microsoft.com>
Date: Thu, 23 Jun 2022 20:38:20 -0700
Mitigate crash that can occur when installed version is null (#2278)
Diffstat:
2 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/src/AppInstallerRepositoryCore/CompositeSource.cpp b/src/AppInstallerRepositoryCore/CompositeSource.cpp
@@ -343,7 +343,11 @@ namespace AppInstaller::Repository
{
if (m_installedPackage)
{
- return std::make_shared<CompositeInstalledVersion>(m_installedPackage->GetInstalledVersion(), m_trackingSource, m_overrideInstalledVersion);
+ auto installedVersion = m_installedPackage->GetInstalledVersion();
+ if (installedVersion)
+ {
+ return std::make_shared<CompositeInstalledVersion>(std::move(installedVersion), m_trackingSource, m_overrideInstalledVersion);
+ }
}
return {};
@@ -444,10 +448,14 @@ namespace AppInstaller::Repository
{
if (m_installedPackage && m_availablePackage)
{
- auto installedType = Manifest::ConvertToInstallerTypeEnum(m_installedPackage->GetInstalledVersion()->GetMetadata()[PackageVersionMetadata::InstalledType]);
- if (Manifest::DoesInstallerTypeSupportArpVersionRange(installedType))
+ auto installedVersion = m_installedPackage->GetInstalledVersion();
+ if (installedVersion)
{
- m_overrideInstalledVersion = GetMappedInstalledVersion(m_installedPackage->GetInstalledVersion()->GetProperty(PackageVersionProperty::Version), m_availablePackage);
+ auto installedType = Manifest::ConvertToInstallerTypeEnum(installedVersion->GetMetadata()[PackageVersionMetadata::InstalledType]);
+ if (Manifest::DoesInstallerTypeSupportArpVersionRange(installedType))
+ {
+ m_overrideInstalledVersion = GetMappedInstalledVersion(installedVersion->GetProperty(PackageVersionProperty::Version), m_availablePackage);
+ }
}
}
}
diff --git a/src/AppInstallerRepositoryCore/Microsoft/Schema/1_0/Interface_1_0.cpp b/src/AppInstallerRepositoryCore/Microsoft/Schema/1_0/Interface_1_0.cpp
@@ -101,6 +101,11 @@ namespace AppInstaller::Repository::Microsoft::Schema::V1_0
// Get the last version in the list (the highest version) and its rowid
const std::string& latestVersion = versions.back().ToString();
versionIdOpt = VersionTable::SelectIdByValue(connection, latestVersion);
+
+ if (!versionIdOpt)
+ {
+ AICLI_LOG(Repo, Warning, << "Did not find a Version row for the latest version { " << latestVersion << " }");
+ }
}
else
{
@@ -109,7 +114,7 @@ namespace AppInstaller::Repository::Microsoft::Schema::V1_0
if (!versionIdOpt)
{
- AICLI_LOG(Repo, Info, << "Did not find a Version { " << version << " }");
+ AICLI_LOG(Repo, Info, << "Did not find a Version for { " << version << " }");
return {};
}