From 094b87400ccbce81f934e9ace6c7229928979ade Mon Sep 17 00:00:00 2001 From: JohnMcPMS Date: Thu, 23 Jun 2022 20:38:20 -0700 Subject: [PATCH] Mitigate crash that can occur when installed version is null (#2278) --- .../CompositeSource.cpp | 16 ++++++++++++---- .../Microsoft/Schema/1_0/Interface_1_0.cpp | 7 ++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/AppInstallerRepositoryCore/CompositeSource.cpp b/src/AppInstallerRepositoryCore/CompositeSource.cpp index f2cd8b0642..7289b40a72 100644 --- a/src/AppInstallerRepositoryCore/CompositeSource.cpp +++ b/src/AppInstallerRepositoryCore/CompositeSource.cpp @@ -338,7 +338,11 @@ namespace AppInstaller::Repository { if (m_installedPackage) { - return std::make_shared(m_installedPackage->GetInstalledVersion(), m_trackingSource, m_overrideInstalledVersion); + auto installedVersion = m_installedPackage->GetInstalledVersion(); + if (installedVersion) + { + return std::make_shared(std::move(installedVersion), m_trackingSource, m_overrideInstalledVersion); + } } return {}; @@ -439,10 +443,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 index ae340579c0..5b97c3c423 100644 --- 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 {}; }