Skip to content

Commit

Permalink
Mitigate crash that can occur when installed version is null (#2278)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnMcPMS committed Jun 24, 2022
1 parent 6c0aafa commit 094b874
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
16 changes: 12 additions & 4 deletions src/AppInstallerRepositoryCore/CompositeSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,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 {};
Expand Down Expand Up @@ -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);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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 {};
}

Expand Down

0 comments on commit 094b874

Please sign in to comment.