Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add try/catch when reading upgrade codes #3637

Merged
merged 1 commit into from Sep 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 24 additions & 13 deletions src/AppInstallerRepositoryCore/Microsoft/ARPHelper.cpp
Expand Up @@ -77,28 +77,39 @@ namespace AppInstaller::Repository::Microsoft
AICLI_LOG(Repo, Info, << "Reading MSI UpgradeCodes");
std::map<std::string, std::string> upgradeCodes;

// There is no UpgradeCodes key on the x86 view of the registry
Registry::Key upgradeCodesKey = Registry::Key::OpenIfExists(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\UpgradeCodes", 0, KEY_READ | KEY_WOW64_64KEY);

if (upgradeCodesKey)
try
{
for (const auto& upgradeCodeKeyRef : upgradeCodesKey)
// There is no UpgradeCodes key on the x86 view of the registry
Registry::Key upgradeCodesKey = Registry::Key::OpenIfExists(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\UpgradeCodes", 0, KEY_READ | KEY_WOW64_64KEY);

if (upgradeCodesKey)
{
auto upgradeCode = TryUnpackUpgradeCodeGuid(upgradeCodeKeyRef.Name());
if (upgradeCode)
for (const auto& upgradeCodeKeyRef : upgradeCodesKey)
{
auto upgradeCodeKey = upgradeCodeKeyRef.Open();
for (const auto& productCodeValue : upgradeCodeKey.Values())
std::string keyName;

try
{
auto productCode = TryUnpackUpgradeCodeGuid(productCodeValue.Name());
if (productCode)
keyName = upgradeCodeKeyRef.Name();
auto upgradeCode = TryUnpackUpgradeCodeGuid(keyName);
if (upgradeCode)
{
upgradeCodes[*productCode] = *upgradeCode;
auto upgradeCodeKey = upgradeCodeKeyRef.Open();
for (const auto& productCodeValue : upgradeCodeKey.Values())
{
auto productCode = TryUnpackUpgradeCodeGuid(productCodeValue.Name());
if (productCode)
{
upgradeCodes[*productCode] = *upgradeCode;
}
}
}
}
CATCH_LOG_MSG("Failed to read upgrade code: %hs", keyName.c_str());
}
}
}
}
CATCH_LOG_MSG("Failed to read upgrade codes.");

return upgradeCodes;
}
Expand Down